From 0f6ce9bd01ac104ab72ad33b05812f374a86eeac Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 5 May 2019 08:20:24 +0100 Subject: [PATCH] Remove some spurious null pointer tests. In load_openssh_new_key, ret->keyblob is never null any more: now that it's a strbuf instead of a bare realloc()ed string, it's at worst an _empty_ strbuf. Secondly, as Coverity pointed out, the null pointer check was too late to do any good in the first place - the previous clause of the same if condition would already have dereferenced it! In test_mac in the auxiliary testsc program, there's no actual reason I would ever have called it with null ssh_mac pointer - it would mean 'don't test anything'! Looks as if I just copy-pasted the MAC parts of the cipher+MAC setup code in test_cipher. --- import.c | 2 +- testsc.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/import.c b/import.c index c4410782..a11d1602 100644 --- a/import.c +++ b/import.c @@ -1166,7 +1166,7 @@ static struct openssh_new_key *load_openssh_new_key(const Filename *filename, fclose(fp); fp = NULL; - if (ret->keyblob->len == 0 || !ret->keyblob) { + if (ret->keyblob->len == 0) { errmsg = "key body not present"; goto error; } diff --git a/testsc.c b/testsc.c index f26a42ba..4e457617 100644 --- a/testsc.c +++ b/testsc.c @@ -1303,9 +1303,9 @@ static void test_mac(const ssh2_macalg *malg) return; } - uint8_t *mkey = malg ? snewn(malg->keylen, uint8_t) : NULL; + uint8_t *mkey = snewn(malg->keylen, uint8_t); size_t datalen = 256; - size_t maclen = malg ? malg->len : 0; + size_t maclen = malg->len; uint8_t *data = snewn(datalen + maclen, uint8_t); /* Preliminarily key the MAC, to avoid the divergence of control