mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user