diff options
author | Nick Mathewson <nickm@torproject.org> | 2015-06-22 13:51:56 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2015-06-22 13:51:56 -0400 |
commit | e0b7598833238766b157f8eb799f448dac4c1283 (patch) | |
tree | 454d8d79c9cdd25093f63eeb0db9899cbdd8142c /src/test | |
parent | c8cb55659acca96530a1d7f54bb96cac84626e17 (diff) | |
download | tor-e0b7598833238766b157f8eb799f448dac4c1283.tar.gz tor-e0b7598833238766b157f8eb799f448dac4c1283.zip |
Repair breakage in early-error case of microdesc parsing
When I fixed #11243, I made it so we would take the digest of a
descriptor before tokenizing it, so we could desist from download
attempts if parsing failed. But when I did that, I didn't remove an
assertion that the descriptor began with "onion-key". Usually, this
was enforced by "find_start_of_next_microdescriptor", but when
find_start_of_next_microdescriptor returned NULL, the assertion was
triggered.
Fixes bug 16400. Thanks to torkeln for reporting and
cypherpunks_backup for diagnosing and writing the first fix here.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/test_microdesc.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/test/test_microdesc.c b/src/test/test_microdesc.c index fb3df77edc..c0376348dd 100644 --- a/src/test/test_microdesc.c +++ b/src/test/test_microdesc.c @@ -713,12 +713,46 @@ test_md_reject_cache(void *arg) tor_free(mock_ns_val); } +static void +test_md_corrupt_desc(void *arg) +{ + char *cp = NULL; + smartlist_t *sl = NULL; + (void) arg; + + sl = microdescs_add_to_cache(get_microdesc_cache(), + "@last-listed 2015-06-22 10:00:00\n" + "onion-k\n", + NULL, SAVED_IN_JOURNAL, 0, time(NULL), NULL); + tt_int_op(smartlist_len(sl), ==, 0); + smartlist_free(sl); + + sl = microdescs_add_to_cache(get_microdesc_cache(), + "@last-listed 2015-06-22 10:00:00\n" + "wiggly\n", + NULL, SAVED_IN_JOURNAL, 0, time(NULL), NULL); + tt_int_op(smartlist_len(sl), ==, 0); + smartlist_free(sl); + + tor_asprintf(&cp, "%s\n%s", test_md1, "@foobar\nonion-wobble\n"); + + sl = microdescs_add_to_cache(get_microdesc_cache(), + cp, cp+strlen(cp), + SAVED_IN_JOURNAL, 0, time(NULL), NULL); + tt_int_op(smartlist_len(sl), ==, 0); + smartlist_free(sl); + + done: + tor_free(cp); +} + struct testcase_t microdesc_tests[] = { { "cache", test_md_cache, TT_FORK, NULL, NULL }, { "broken_cache", test_md_cache_broken, TT_FORK, NULL, NULL }, { "generate", test_md_generate, 0, NULL, NULL }, { "parse", test_md_parse, 0, NULL, NULL }, { "reject_cache", test_md_reject_cache, TT_FORK, NULL, NULL }, + { "corrupt_desc", test_md_corrupt_desc, TT_FORK, NULL, NULL }, END_OF_TESTCASES }; |