aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_hs.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2017-05-03 09:26:17 -0400
committerDavid Goulet <dgoulet@torproject.org>2017-05-03 09:26:17 -0400
commit90b840af60a43eb8f8f66080ff5f53dda9df717b (patch)
tree4201e5640c0c53067feacd436459a8af9957454d /src/test/test_hs.c
parente0b1fd4d3da05701c0970dabd93010d6c7550d43 (diff)
downloadtor-90b840af60a43eb8f8f66080ff5f53dda9df717b.tar.gz
tor-90b840af60a43eb8f8f66080ff5f53dda9df717b.zip
control: Fix NULL pointer access in HS desc event
This was introduced 90562fc23a7ce61f3660b507d9991a27af2eae37 adding a code path where we pass a NULL pointer for the HSDir fingerprint to the control event subsystem. The HS desc failed function wasn't handling properly that pointer for a NULL value. Two unit tests are also added in this commit to make sure we handle properly the case of a NULL hsdir fingerprint and a NULL content as well. Fixes #22138 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_hs.c')
-rw-r--r--src/test/test_hs.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/test/test_hs.c b/src/test/test_hs.c
index c3457c43da..b4817a21ea 100644
--- a/src/test/test_hs.c
+++ b/src/test/test_hs.c
@@ -210,9 +210,30 @@ test_hs_desc_event(void *arg)
tt_str_op(received_msg,OP_EQ, expected_msg);
tor_free(received_msg);
- /* test valid content. */
+ /* test no HSDir fingerprint type */
+ rend_query.auth_type = REND_NO_AUTH;
+ control_event_hs_descriptor_failed(&rend_query.base_, NULL,
+ "QUERY_NO_HSDIR");
+ expected_msg = "650 HS_DESC FAILED "STR_HS_ADDR" NO_AUTH " \
+ "UNKNOWN REASON=QUERY_NO_HSDIR\r\n";
+ tt_assert(received_msg);
+ tt_str_op(received_msg,OP_EQ, expected_msg);
+ tor_free(received_msg);
+
+ /* Test invalid content with no HSDir fingerprint. */
char *exp_msg;
control_event_hs_descriptor_content(rend_query.onion_address,
+ STR_HS_CONTENT_DESC_ID, NULL, NULL);
+ tor_asprintf(&exp_msg, "650+HS_DESC_CONTENT " STR_HS_ADDR " "\
+ STR_HS_CONTENT_DESC_ID " UNKNOWN" \
+ "\r\n\r\n.\r\n650 OK\r\n");
+ tt_assert(received_msg);
+ tt_str_op(received_msg, OP_EQ, exp_msg);
+ tor_free(received_msg);
+ tor_free(exp_msg);
+
+ /* test valid content. */
+ control_event_hs_descriptor_content(rend_query.onion_address,
STR_HS_CONTENT_DESC_ID, HSDIR_EXIST_ID,
hs_desc_content);
tor_asprintf(&exp_msg, "650+HS_DESC_CONTENT " STR_HS_ADDR " "\