From c100c5c69b4fd3b464b2395263e77cc6e1051ef3 Mon Sep 17 00:00:00 2001 From: teor Date: Sat, 3 Dec 2016 06:25:46 +1100 Subject: [PATCH 1/6] Refactor poison_dir allocation and free in test_single_onion_poisoning This pattern is much less error-prone when future changes are made. --- src/test/test_hs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/test/test_hs.c b/src/test/test_hs.c index f4ba7f9e0..1039c64fd 100644 --- a/src/test/test_hs.c +++ b/src/test/test_hs.c @@ -541,6 +541,7 @@ test_single_onion_poisoning(void *arg) rend_service_t *service_2 = tor_malloc_zero(sizeof(rend_service_t)); char *dir2 = tor_strdup(get_fname_rnd("test_hs_dir2")); smartlist_t *services = smartlist_new(); + char *poison_path = NULL; /* No services, no service to verify, no problem! */ mock_options->HiddenServiceSingleHopMode = 0; @@ -706,9 +707,9 @@ test_single_onion_poisoning(void *arg) /* Now remove the poisoning from the first service, and we have the opposite * problem. */ - char *poison_path = rend_service_sos_poison_path(service_1); + poison_path = rend_service_sos_poison_path(service_1); + tt_assert(poison_path); ret = unlink(poison_path); - tor_free(poison_path); tt_assert(ret == 0); /* Unpoisoned service directories with previous keys are ok, as are empty @@ -765,6 +766,7 @@ test_single_onion_poisoning(void *arg) tt_assert(ret == 0); done: + tor_free(poison_path); tor_free(dir1); tor_free(dir2); /* The test harness deletes the directories at exit */ From fdd368d6564e955422337af53e0723b571b8da57 Mon Sep 17 00:00:00 2001 From: teor Date: Sat, 3 Dec 2016 06:27:32 +1100 Subject: [PATCH 2/6] Remove a double-free in test_single_onion_poisoning We were freeing both dir{1,2} directly, and service_{1,2}->directory via rend_service_free, even though they are the same pointer. --- src/test/test_hs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/test_hs.c b/src/test/test_hs.c index 1039c64fd..c7aaace03 100644 --- a/src/test/test_hs.c +++ b/src/test/test_hs.c @@ -570,8 +570,8 @@ test_single_onion_poisoning(void *arg) tt_assert(ret == 0); } - service_1->directory = dir1; - service_2->directory = dir2; + service_1->directory = tor_strdup(dir1); + service_2->directory = tor_strdup(dir2); /* The services own the directory pointers now */ dir1 = dir2 = NULL; /* Add port to service 1 */ From 8d42aab3f68d7d01c87bbfe60c30c438d70437c3 Mon Sep 17 00:00:00 2001 From: teor Date: Sat, 3 Dec 2016 06:30:06 +1100 Subject: [PATCH 3/6] Add a missing return value check in test_single_onion_poisoning --- src/test/test_hs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/test_hs.c b/src/test/test_hs.c index c7aaace03..067e6b4bf 100644 --- a/src/test/test_hs.c +++ b/src/test/test_hs.c @@ -688,6 +688,7 @@ test_single_onion_poisoning(void *arg) /* Now add the second service: it has no key and no poison file */ ret = rend_service_check_dir_and_add(services, mock_options, service_2, 0); + tt_assert(ret == 0); /* A new service, and an existing poisoned service. Not ok. */ mock_options->HiddenServiceSingleHopMode = 0; From e8ce57e6e8e8b245f0378ef3aae4fdc55534cbd8 Mon Sep 17 00:00:00 2001 From: teor Date: Sat, 3 Dec 2016 06:30:58 +1100 Subject: [PATCH 4/6] Move a comment in test_single_onion_poisoning --- src/test/test_hs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/test_hs.c b/src/test/test_hs.c index 067e6b4bf..690e07e6f 100644 --- a/src/test/test_hs.c +++ b/src/test/test_hs.c @@ -767,10 +767,10 @@ test_single_onion_poisoning(void *arg) tt_assert(ret == 0); done: + /* The test harness deletes the directories at exit */ tor_free(poison_path); tor_free(dir1); tor_free(dir2); - /* The test harness deletes the directories at exit */ smartlist_free(services); rend_service_free(service_1); rend_service_free(service_2); From ebf243bc5b3ad083eaee2d412520e5d617473792 Mon Sep 17 00:00:00 2001 From: teor Date: Sat, 3 Dec 2016 06:35:45 +1100 Subject: [PATCH 5/6] Changes file for 20864 --- changes/bug20864 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changes/bug20864 diff --git a/changes/bug20864 b/changes/bug20864 new file mode 100644 index 000000000..079e609e2 --- /dev/null +++ b/changes/bug20864 @@ -0,0 +1,4 @@ + o Minor bugfixes (hidden services): + - Remove a double-free in the single onion service unit test. Stop + ignoring a return value. Make future changes less error-prone. + Fixes bug 20864; bugfix on 20638; not in any released version of tor. From 42ec60ecfbff39c454945bc52def0df196ec38b8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 5 Dec 2016 08:12:10 -0500 Subject: [PATCH 6/6] Fix changes file for 20864: 20638 _did_ get into 0.2.9 --- changes/bug20864 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/changes/bug20864 b/changes/bug20864 index 079e609e2..7b8c70fad 100644 --- a/changes/bug20864 +++ b/changes/bug20864 @@ -1,4 +1,4 @@ - o Minor bugfixes (hidden services): + o Minor bugfixes (unit tests, hidden services): - Remove a double-free in the single onion service unit test. Stop ignoring a return value. Make future changes less error-prone. - Fixes bug 20864; bugfix on 20638; not in any released version of tor. + Fixes bug 20864; bugfix on 0.2.9.6-rc.