From 34a2cbb249cdaf23c88b93972a9216926a8d7551 Mon Sep 17 00:00:00 2001 From: George Kadianakis Date: Mon, 10 Sep 2018 16:47:28 +0300 Subject: [PATCH 1/4] Address coverity warnings (CID 1439133/1439132). >>>> CID 1439133: Null pointer dereferences (REVERSE_INULL) >>>> Null-checking "fields" suggests that it may be null, but it >>>> has already been dereferenced on all paths leading to the check. >>>> CID 1439132: Null pointer dereferences (REVERSE_INULL) >>>> Null-checking "fields" suggests that it may be null, but it >>>> has already been dereferenced on all paths leading to the check. --- src/feature/hs/hs_client.c | 7 +++---- src/feature/hs/hs_service.c | 7 +++---- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/feature/hs/hs_client.c b/src/feature/hs/hs_client.c index 6f031eb3b9..a6384b87a3 100644 --- a/src/feature/hs/hs_client.c +++ b/src/feature/hs/hs_client.c @@ -1524,10 +1524,9 @@ parse_auth_file_content(const char *client_key_str) if (seckey_b32) { memwipe(seckey_b32, 0, strlen(seckey_b32)); } - if (fields) { - SMARTLIST_FOREACH(fields, char *, s, tor_free(s)); - smartlist_free(fields); - } + tor_assert(fields); + SMARTLIST_FOREACH(fields, char *, s, tor_free(s)); + smartlist_free(fields); return auth; } diff --git a/src/feature/hs/hs_service.c b/src/feature/hs/hs_service.c index 43e5626a57..30d23eb771 100644 --- a/src/feature/hs/hs_service.c +++ b/src/feature/hs/hs_service.c @@ -1192,10 +1192,9 @@ parse_authorized_client(const char *client_key_str) if (pubkey_b32) { memwipe(pubkey_b32, 0, strlen(pubkey_b32)); } - if (fields) { - SMARTLIST_FOREACH(fields, char *, s, tor_free(s)); - smartlist_free(fields); - } + tor_assert(fields); + SMARTLIST_FOREACH(fields, char *, s, tor_free(s)); + smartlist_free(fields); return client; } From 58d74ad943ee3e2d428b17fd08c2de1a093f6a27 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 10 Sep 2018 10:20:58 -0400 Subject: [PATCH 2/4] test: Fix coverity CID 1439131 Simple uninitialized object that we could free in an HS v3 unit test. Signed-off-by: David Goulet --- src/test/test_hs_descriptor.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/test_hs_descriptor.c b/src/test/test_hs_descriptor.c index 4889281cb1..90f2be2906 100644 --- a/src/test/test_hs_descriptor.c +++ b/src/test/test_hs_descriptor.c @@ -675,6 +675,8 @@ test_decode_bad_signature(void *arg) (void) arg; + memset(&desc_plaintext, 0, sizeof(desc_plaintext)); + /* Update approx time to dodge cert expiration */ update_approx_time(1502661599); From 064d3e7497216c78b05ccd30422dc522bc337db8 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 10 Sep 2018 10:22:31 -0400 Subject: [PATCH 3/4] test: Fix coverity CID 1439130 Trivial fix of removing an uneeded NULL check in an HS v3 unit test. Signed-off-by: David Goulet --- src/test/test_hs_service.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index 6a061eaea4..bceeafd149 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -563,9 +563,7 @@ test_load_keys_with_client_auth(void *arg) } SMARTLIST_FOREACH_END(pubkey_b32); done: - if (pubkey_b32_list) { - SMARTLIST_FOREACH(pubkey_b32_list, char *, s, tor_free(s)); - } + SMARTLIST_FOREACH(pubkey_b32_list, char *, s, tor_free(s)); smartlist_free(pubkey_b32_list); tor_free(hsdir_v3); hs_free_all(); From 7ff67d0e90d1cdf206747649df79dbb88a7467a8 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 10 Sep 2018 10:28:35 -0400 Subject: [PATCH 4/4] test: Fix coverity CID 1439129 One HSv3 unit test used "tor_memeq()" without checking the return value. This commit changes that to use "tt_mem_op()" to actually make the test validate something :). Signed-off-by: David Goulet --- src/test/hs_test_helpers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/hs_test_helpers.c b/src/test/hs_test_helpers.c index 4e13ba43a7..dcec1b9d48 100644 --- a/src/test/hs_test_helpers.c +++ b/src/test/hs_test_helpers.c @@ -241,11 +241,11 @@ hs_helper_desc_equal(const hs_descriptor_t *desc1, hs_desc_authorized_client_t *client1 = smartlist_get(desc1->superencrypted_data.clients, i), *client2 = smartlist_get(desc2->superencrypted_data.clients, i); - tor_memeq(client1->client_id, client2->client_id, + tt_mem_op(client1->client_id, OP_EQ, client2->client_id, sizeof(client1->client_id)); - tor_memeq(client1->iv, client2->iv, + tt_mem_op(client1->iv, OP_EQ, client2->iv, sizeof(client1->iv)); - tor_memeq(client1->encrypted_cookie, client2->encrypted_cookie, + tt_mem_op(client1->encrypted_cookie, OP_EQ, client2->encrypted_cookie, sizeof(client1->encrypted_cookie)); } }