Revise networkstatus parsing code to use lengths

This way the networkstatus can be parsed without being
NUL-terminated, so we can implement 27244 and mmap our consensus objects.
This commit is contained in:
Nick Mathewson
2018-09-11 10:32:17 -04:00
parent e014b72b73
commit abaca3fc8c
9 changed files with 85 additions and 47 deletions
+3 -3
View File
@@ -59,13 +59,13 @@ int
fuzz_main(const uint8_t *data, size_t sz)
{
networkstatus_t *ns;
char *str = tor_memdup_nulterm(data, sz);
const char *eos = NULL;
networkstatus_type_t tp = NS_TYPE_CONSENSUS;
if (tor_memstr(data, MIN(sz, 1024), "tus vote"))
tp = NS_TYPE_VOTE;
const char *what = (tp == NS_TYPE_CONSENSUS) ? "consensus" : "vote";
ns = networkstatus_parse_vote_from_string(str,
ns = networkstatus_parse_vote_from_string((const char *)data,
sz,
&eos,
tp);
if (ns) {
@@ -74,6 +74,6 @@ fuzz_main(const uint8_t *data, size_t sz)
} else {
log_debug(LD_GENERAL, "Parsing as %s failed", what);
}
tor_free(str);
return 0;
}
+8 -8
View File
@@ -52,24 +52,24 @@ fuzz_cleanup(void)
int
fuzz_main(const uint8_t *data, size_t sz)
{
char *str = tor_memdup_nulterm(data, sz);
const char *s;
routerstatus_t *rs_ns = NULL, *rs_md = NULL, *rs_vote = NULL;
vote_routerstatus_t *vrs = tor_malloc_zero(sizeof(*vrs));
smartlist_t *tokens = smartlist_new();
const char *eos = (const char *)data + sz;
s = str;
rs_ns = routerstatus_parse_entry_from_string(area, &s, tokens,
s = (const char *)data;
rs_ns = routerstatus_parse_entry_from_string(area, &s, eos, tokens,
NULL, NULL, 26, FLAV_NS);
tor_assert(smartlist_len(tokens) == 0);
s = str;
rs_md = routerstatus_parse_entry_from_string(area, &s, tokens,
s = (const char *)data;
rs_md = routerstatus_parse_entry_from_string(area, &s, eos, tokens,
NULL, NULL, 26, FLAV_MICRODESC);
tor_assert(smartlist_len(tokens) == 0);
s = str;
rs_vote = routerstatus_parse_entry_from_string(area, &s, tokens,
s = (const char *)data;
rs_vote = routerstatus_parse_entry_from_string(area, &s, eos, tokens,
dummy_vote, vrs, 26, FLAV_NS);
tor_assert(smartlist_len(tokens) == 0);
@@ -81,6 +81,6 @@ fuzz_main(const uint8_t *data, size_t sz)
vote_routerstatus_free(vrs);
memarea_clear(area);
smartlist_free(tokens);
tor_free(str);
return 0;
}