diff options
author | Anderson Toshiyuki Sasaki <ansasaki@redhat.com> | 2018-09-13 16:15:57 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2018-09-18 10:19:59 +0200 |
commit | 31f24ed23ead1f4bc8a98c53f25368b1ab51f397 (patch) | |
tree | f5c854121979d4035107477a2a6a940f9e926e97 | |
parent | 82c3faa44d99063f9d866767d3f9379e9f0d29b0 (diff) | |
download | libssh-31f24ed23ead1f4bc8a98c53f25368b1ab51f397.tar.gz libssh-31f24ed23ead1f4bc8a98c53f25368b1ab51f397.tar.xz libssh-31f24ed23ead1f4bc8a98c53f25368b1ab51f397.zip |
tests: Add null checks and frees in torture_pki_dsa.c
These frees are unnecessary because the negative tests should not
allocate the keys, but the static analyser reports memory leak errors.
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
-rw-r--r-- | tests/unittests/torture_pki_dsa.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/unittests/torture_pki_dsa.c b/tests/unittests/torture_pki_dsa.c index 6a5331ba..e8d03904 100644 --- a/tests/unittests/torture_pki_dsa.c +++ b/tests/unittests/torture_pki_dsa.c @@ -149,6 +149,7 @@ static void torture_pki_dsa_write_privkey(void **state) NULL, &privkey); assert_true(rc == 0); + assert_non_null(privkey); rc = ssh_key_cmp(origkey, privkey, SSH_KEY_CMP_PRIVATE); assert_true(rc == 0); @@ -163,6 +164,7 @@ static void torture_pki_dsa_write_privkey(void **state) NULL, &origkey); assert_true(rc == 0); + assert_non_null(origkey); unlink(LIBSSH_DSA_TESTKEY_PASSPHRASE); rc = ssh_pki_export_privkey_file(origkey, @@ -256,6 +258,9 @@ static void torture_pki_dsa_import_privkey_base64_passphrase(void **state) &key); assert_true(rc == -1); + /* This free in unnecessary, but the static analyser does not know */ + ssh_key_free(key); + #ifndef HAVE_LIBCRYPTO /* test if it returns -1 if passphrase is NULL */ /* libcrypto asks for a passphrase, so skip this test */ @@ -265,6 +270,9 @@ static void torture_pki_dsa_import_privkey_base64_passphrase(void **state) NULL, &key); assert_true(rc == -1); + + /* This free in unnecessary, but the static analyser does not know */ + ssh_key_free(key); #endif /* HAVE_LIBCRYPTO */ } @@ -491,6 +499,7 @@ static void torture_pki_dsa_duplicate_key(void **state) rc = ssh_pki_import_pubkey_file(LIBSSH_DSA_TESTKEY ".pub", &pubkey); assert_true(rc == 0); + assert_non_null(pubkey); rc = ssh_pki_export_pubkey_base64(pubkey, &b64_key); assert_true(rc == 0); @@ -502,15 +511,19 @@ static void torture_pki_dsa_duplicate_key(void **state) NULL, &privkey); assert_true(rc == 0); + assert_non_null(privkey); privkey_dup = ssh_key_dup(privkey); assert_true(privkey_dup != NULL); + assert_non_null(privkey_dup); rc = ssh_pki_export_privkey_to_pubkey(privkey, &pubkey); assert_true(rc == SSH_OK); + assert_non_null(pubkey); rc = ssh_pki_export_pubkey_base64(pubkey, &b64_key_gen); assert_true(rc == 0); + assert_non_null(b64_key_gen); assert_string_equal(b64_key, b64_key_gen); |