aboutsummaryrefslogtreecommitdiff
path: root/src/test/fuzz/fuzz_socks.c
blob: 4e7cb4d48d0e8b99078ea8563d3a965259d3daed (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
50
/* Copyright (c) 2016-2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */

#include "orconfig.h"

#define BUFFERS_PRIVATE
#include "core/or/or.h"

#include "lib/buf/buffers.h"
#include "lib/err/backtrace.h"
#include "lib/log/log.h"
#include "core/proto/proto_socks.h"
#include "feature/client/addressmap.h"

#include "test/fuzz/fuzzing.h"

int
fuzz_init(void)
{
  addressmap_init();
  return 0;
}

int
fuzz_cleanup(void)
{
  addressmap_free_all();
  return 0;
}

int
fuzz_main(const uint8_t *stdin_buf, size_t data_size)
{
  buf_t *buffer = buf_new_with_data((char*)stdin_buf, data_size);
  if (!buffer) {
    tor_assert(data_size==0);
    buffer = buf_new();
  }

  socks_request_t *request = socks_request_new();

  int r = fetch_from_buf_socks(buffer, request, 0, 0);
  log_info(LD_GENERAL, "Socks request status: %d", r);

  /* Reset. */
  buf_free(buffer);
  socks_request_free(request);

  return 0;
}