From 5d7fe5f83aafcf787f426cff450412d668d1128d Mon Sep 17 00:00:00 2001 From: Jonathan McDowell Date: Fri, 1 Nov 2013 22:00:25 -0700 Subject: [PATCH] Don't store a key if we can't get the keyid If the get_keyid call fails for a key then we shouldn't be storing it, so don't. --- keydb_db4.c | 5 ++++- keydb_file.c | 5 ++++- keydb_fs.c | 5 ++++- keydb_keyd.c | 5 ++++- keydb_pg.c | 5 ++++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/keydb_db4.c b/keydb_db4.c index 0507511..f4fffa5 100644 --- a/keydb_db4.c +++ b/keydb_db4.c @@ -1180,7 +1180,10 @@ static int db4_store_key(struct openpgp_publickey *publickey, bool intrans, bool deadlock = false; struct skshash hash; - get_keyid(publickey, &keyid); + if (get_keyid(publickey, &keyid) != ONAK_E_OK) { + logthing(LOGTHING_ERROR, "Couldn't find key ID for key."); + return 0; + } if (!intrans) { db4_starttrans(); diff --git a/keydb_file.c b/keydb_file.c index 65e71f5..4321a68 100644 --- a/keydb_file.c +++ b/keydb_file.c @@ -130,7 +130,10 @@ static int file_store_key(struct openpgp_publickey *publickey, bool intrans, int fd = -1; uint64_t keyid; - get_keyid(publickey, &keyid); + if (get_keyid(publickey, &keyid) != ONAK_E_OK) { + logthing(LOGTHING_ERROR, "Couldn't find key ID for key."); + return 0; + } snprintf(keyfile, 1023, "%s/0x%" PRIX64, config.db_dir, keyid & 0xFFFFFFFF); fd = open(keyfile, O_WRONLY | O_CREAT, 0664); // | O_EXLOCK); diff --git a/keydb_fs.c b/keydb_fs.c index eacf1c6..b7117be 100644 --- a/keydb_fs.c +++ b/keydb_fs.c @@ -336,7 +336,10 @@ static int fs_store_key(struct openpgp_publickey *publickey, bool intrans, uint32_t hashid; int i = 0; - get_keyid(publickey, &keyid); + if (get_keyid(publickey, &keyid) != ONAK_E_OK) { + logthing(LOGTHING_ERROR, "Couldn't find key ID for key."); + return 0; + } if (!intrans) fs_starttrans(); diff --git a/keydb_keyd.c b/keydb_keyd.c index 26f2f27..4820ee3 100644 --- a/keydb_keyd.c +++ b/keydb_keyd.c @@ -274,7 +274,10 @@ static int keyd_store_key(struct openpgp_publickey *publickey, bool intrans, uint32_t cmd = KEYD_CMD_STORE; uint64_t keyid; - get_keyid(publickey, &keyid); + if (get_keyid(publickey, &keyid) != ONAK_E_OK) { + logthing(LOGTHING_ERROR, "Couldn't find key ID for key."); + return 0; + } if (update) { keyd_delete_key(keyid, false); diff --git a/keydb_pg.c b/keydb_pg.c index 1ec0a1a..480f1f1 100644 --- a/keydb_pg.c +++ b/keydb_pg.c @@ -376,7 +376,10 @@ static int pg_store_key(struct openpgp_publickey *publickey, bool intrans, PQclear(result); } - get_keyid(publickey, &keyid); + if (get_keyid(publickey, &keyid) != ONAK_E_OK) { + logthing(LOGTHING_ERROR, "Couldn't find key ID for key."); + return 0; + } /* * Delete the key if we already have it. -- 2.39.5