tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

fuzz_extrainfo.c (1547B)


      1 /* Copyright (c) 2016-2021, The Tor Project, Inc. */
      2 /* See LICENSE for licensing information */
      3 #define SIGCOMMON_PRIVATE
      4 #include "core/or/or.h"
      5 #include "feature/dirparse/routerparse.h"
      6 #include "feature/dirparse/sigcommon.h"
      7 #include "feature/dirparse/unparseable.h"
      8 #include "feature/nodelist/routerlist.h"
      9 #include "feature/relay/routerkeys.h"
     10 #include "test/fuzz/fuzzing.h"
     11 
     12 static void
     13 mock_dump_desc__nodump(const char *desc, const char *type)
     14 {
     15  (void)desc;
     16  (void)type;
     17 }
     18 
     19 static int
     20 mock_router_produce_hash_final__nohash(char *digest,
     21                                       const char *start, size_t len,
     22                                       digest_algorithm_t alg)
     23 {
     24  (void)start;
     25  (void)len;
     26  /* we could look at start[..] */
     27  if (alg == DIGEST_SHA1)
     28    memset(digest, 0x01, 20);
     29  else
     30    memset(digest, 0x02, 32);
     31  return 0;
     32 }
     33 
     34 int
     35 fuzz_init(void)
     36 {
     37  disable_signature_checking();
     38  MOCK(dump_desc, mock_dump_desc__nodump);
     39  MOCK(router_compute_hash_final, mock_router_produce_hash_final__nohash);
     40  ed25519_init();
     41  return 0;
     42 }
     43 
     44 int
     45 fuzz_cleanup(void)
     46 {
     47  return 0;
     48 }
     49 
     50 int
     51 fuzz_main(const uint8_t *data, size_t sz)
     52 {
     53  extrainfo_t *ei;
     54  const char *str = (const char*) data;
     55  int again = 0;
     56  ei = extrainfo_parse_entry_from_string((const char *)str,
     57                                         str+sz,
     58                                         0, NULL, &again);
     59  if (ei) {
     60    log_debug(LD_GENERAL, "Parsing okay");
     61    extrainfo_free(ei);
     62  } else {
     63    log_debug(LD_GENERAL, "Parsing failed");
     64  }
     65  return 0;
     66 }