aboutsummaryrefslogtreecommitdiff
path: root/projects/dnsmasq/fuzz_util.c
blob: 7ab723ccd3f569003290da9ee2d0ec0eece5f717 (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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* Copyright 2021 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
      http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "fuzz_header.h"

int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
  // init fuzz garbage collector
  gb_init();

  int succ = init_daemon(&data, &size);
  if (succ == 0) {
    char *t1 = gb_get_null_terminated(&data, &size);
    char *t2 = gb_get_null_terminated(&data, &size);
    if (t1 != NULL && t2 != NULL) {

      // Util logic
      hostname_isequal(t1, t2);

      legal_hostname(t1);
      char *tmp = canonicalise(t2, NULL);
      if (tmp != NULL) {
        free(tmp);
      }

      char *tmp_out = (char *)malloc(30);
      int mac_type;
      parse_hex(t1, (unsigned char *)tmp_out, 30, NULL, NULL);
      parse_hex(t1, (unsigned char *)tmp_out, 30, NULL, &mac_type);
      free(tmp_out);

      wildcard_match(t1, t2);
      if (strlen(t1) < strlen(t2)) {
        wildcard_matchn(t1, t2, strlen(t1));
      } else {
        wildcard_matchn(t1, t2, strlen(t2));
      }
      hostname_issubdomain(t1, t2);

      union all_addr addr1;
      memset(&addr1, 0, sizeof(union all_addr));
      is_name_synthetic(0, t1, &addr1);

      if (size > sizeof(struct dns_header)) {
        hash_questions(data, size, t2);

        rrfilter(data, size, 0);
      }
    }

    fuzz_blockdata_cleanup();
  }

  // cleanup
  gb_cleanup();

  return 0;
}