aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/fuzz_microdesc.c
blob: 3fc709183b1432b19e7372b0a9fa779b4c587f60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Copyright (c) 2016-2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */

#include "core/or/or.h"
#include "feature/dirparse/microdesc_parse.h"
#include "feature/dirparse/unparseable.h"
#include "feature/nodelist/microdesc.h"
#include "lib/crypt_ops/crypto_ed25519.h"

#include "test/fuzz/fuzzing.h"

static void
mock_dump_desc__nodump(const char *desc, const char *type)
{
  (void)desc;
  (void)type;
}

int
fuzz_init(void)
{
  disable_signature_checking();
  MOCK(dump_desc, mock_dump_desc__nodump);
  ed25519_init();
  return 0;
}

int
fuzz_cleanup(void)
{
  return 0;
}

int
fuzz_main(const uint8_t *data, size_t sz)
{
  const char *str = (const char*) data;
  smartlist_t *result = microdescs_parse_from_string((const char *)str,
                                                     str+sz,
                                                     0, SAVED_NOWHERE, NULL);
  if (result) {
    log_debug(LD_GENERAL, "Parsing okay: %d", smartlist_len(result));
    SMARTLIST_FOREACH(result, microdesc_t *, md, microdesc_free(md));
    smartlist_free(result);
  } else {
    log_debug(LD_GENERAL, "Parsing failed");
  }
  return 0;
}