1 /* Copyright (c) 2016-2021, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 #define NS_PARSE_PRIVATE
4 #define NETWORKSTATUS_PRIVATE
5 #include "core/or/or.h"
6 #include "feature/dirauth/dirvote.h"
7 #include "feature/dirparse/ns_parse.h"
8 #include "feature/dirparse/unparseable.h"
9 #include "lib/memarea/memarea.h"
10 #include "feature/nodelist/microdesc.h"
11 #include "feature/nodelist/networkstatus.h"
13 #include "feature/nodelist/networkstatus_st.h"
14 #include "feature/nodelist/vote_routerstatus_st.h"
15 #include "lib/crypt_ops/crypto_ed25519.h"
17 #include "test/fuzz/fuzzing.h"
20 mock_dump_desc__nodump(const char *desc
, const char *type
)
26 static networkstatus_t
*dummy_vote
= NULL
;
27 static memarea_t
*area
= NULL
;
32 disable_signature_checking();
33 MOCK(dump_desc
, mock_dump_desc__nodump
);
36 dummy_vote
= tor_malloc_zero(sizeof(*dummy_vote
));
37 dummy_vote
->known_flags
= smartlist_new();
38 smartlist_split_string(dummy_vote
->known_flags
,
39 DIRVOTE_UNIVERSAL_FLAGS
,
41 smartlist_split_string(dummy_vote
->known_flags
,
42 DIRVOTE_OPTIONAL_FLAGS
,
44 smartlist_sort_strings(dummy_vote
->known_flags
);
51 SMARTLIST_FOREACH(dummy_vote
->known_flags
, char *, cp
, tor_free(cp
));
52 smartlist_free(dummy_vote
->known_flags
);
58 fuzz_main(const uint8_t *data
, size_t sz
)
61 routerstatus_t
*rs_ns
= NULL
, *rs_md
= NULL
, *rs_vote
= NULL
;
62 vote_routerstatus_t
*vrs
= tor_malloc_zero(sizeof(*vrs
));
63 smartlist_t
*tokens
= smartlist_new();
64 const char *eos
= (const char *)data
+ sz
;
66 s
= (const char *)data
;
67 rs_ns
= routerstatus_parse_entry_from_string(area
, &s
, eos
, tokens
,
68 NULL
, NULL
, 26, FLAV_NS
);
69 tor_assert(smartlist_len(tokens
) == 0);
71 s
= (const char *)data
;
72 rs_md
= routerstatus_parse_entry_from_string(area
, &s
, eos
, tokens
,
73 NULL
, NULL
, 26, FLAV_MICRODESC
);
74 tor_assert(smartlist_len(tokens
) == 0);
76 s
= (const char *)data
;
77 rs_vote
= routerstatus_parse_entry_from_string(area
, &s
, eos
, tokens
,
78 dummy_vote
, vrs
, 26, FLAV_NS
);
79 tor_assert(smartlist_len(tokens
) == 0);
82 "ns=%p, md=%p, vote=%p", rs_ns
, rs_md
, rs_vote
);
84 routerstatus_free(rs_md
);
85 routerstatus_free(rs_ns
);
86 vote_routerstatus_free(vrs
);
88 smartlist_free(tokens
);