/src/avahi/fuzz/fuzz-consume-record.c
Line | Count | Source (jump to first uncovered line) |
1 | | /*** |
2 | | This file is part of avahi. |
3 | | |
4 | | avahi is free software; you can redistribute it and/or modify it |
5 | | under the terms of the GNU Lesser General Public License as |
6 | | published by the Free Software Foundation; either version 2.1 of the |
7 | | License, or (at your option) any later version. |
8 | | |
9 | | avahi is distributed in the hope that it will be useful, but WITHOUT |
10 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
11 | | or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General |
12 | | Public License for more details. |
13 | | |
14 | | You should have received a copy of the GNU Lesser General Public |
15 | | License along with avahi; if not, write to the Free Software |
16 | | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
17 | | USA. |
18 | | ***/ |
19 | | |
20 | | #include <stdint.h> |
21 | | #include <string.h> |
22 | | |
23 | | #include "avahi-common/malloc.h" |
24 | | #include "avahi-core/dns.h" |
25 | | #include "avahi-core/log.h" |
26 | | #include "avahi-core/rr-util.h" |
27 | | |
28 | 8.62k | void log_function(AvahiLogLevel level, const char *txt) {} |
29 | | |
30 | 2.63k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
31 | 2.63k | AvahiDnsPacket *p = NULL; |
32 | 2.63k | AvahiRecord *r = NULL, *rs = NULL, *c = NULL; |
33 | 2.63k | uint8_t rdata[AVAHI_DNS_RDATA_MAX]; |
34 | 2.63k | size_t rdata_size; |
35 | 2.63k | int ret; |
36 | | |
37 | 2.63k | avahi_set_log_function(log_function); |
38 | | |
39 | 2.63k | if (!(p = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE))) |
40 | 0 | goto finish; |
41 | | |
42 | 2.63k | memcpy(AVAHI_DNS_PACKET_DATA(p), data, size); |
43 | 2.63k | p->size = size; |
44 | | |
45 | 2.63k | if (!(r = avahi_dns_packet_consume_record(p, NULL))) |
46 | 552 | goto finish; |
47 | | |
48 | 2.07k | ret = avahi_record_is_valid(r); |
49 | 2.07k | assert(ret); |
50 | | |
51 | 2.07k | avahi_record_is_goodbye(r); |
52 | | |
53 | 2.07k | avahi_record_is_link_local_address(r); |
54 | | |
55 | 2.07k | avahi_record_get_estimate_size(r); |
56 | | |
57 | 2.07k | avahi_free(avahi_record_to_string(r)); |
58 | | |
59 | 2.07k | rdata_size = avahi_rdata_serialize(r, rdata, sizeof(rdata)); |
60 | 2.07k | assert(rdata_size != (size_t) -1); |
61 | | |
62 | 2.07k | if (!(rs = avahi_record_new_full(r->key->name, r->key->clazz, r->key->type, r->ttl))) |
63 | 0 | goto finish; |
64 | | |
65 | 2.07k | if (avahi_rdata_parse(rs, rdata, rdata_size) < 0) |
66 | 0 | goto finish; |
67 | | |
68 | 2.07k | ret = avahi_record_is_valid(rs); |
69 | 2.07k | assert(ret); |
70 | | |
71 | 2.07k | ret = avahi_record_equal_no_ttl(r, rs); |
72 | 2.07k | assert(ret); |
73 | | |
74 | 2.07k | ret = avahi_record_lexicographical_compare(r, rs); |
75 | 2.07k | assert(ret == 0); |
76 | | |
77 | 2.07k | if (!(c = avahi_record_copy(r))) |
78 | 0 | goto finish; |
79 | | |
80 | 2.07k | ret = avahi_record_equal_no_ttl(r, c); |
81 | 2.07k | assert(ret); |
82 | | |
83 | 2.07k | ret = avahi_record_lexicographical_compare(r, c); |
84 | 2.07k | assert(ret == 0); |
85 | | |
86 | 2.07k | avahi_record_unref(c); |
87 | 2.07k | if (!(c = avahi_dns_packet_consume_record(p, NULL))) |
88 | 749 | goto finish; |
89 | | |
90 | 1.33k | avahi_record_equal_no_ttl(r, c); |
91 | 1.33k | avahi_record_lexicographical_compare(r, c); |
92 | | |
93 | 1.33k | avahi_dns_packet_free(p); |
94 | 1.33k | if (!(p = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE))) |
95 | 0 | goto finish; |
96 | | |
97 | 1.33k | if (!avahi_dns_packet_append_record(p, r, 0, 0)) |
98 | 99 | goto finish; |
99 | | |
100 | 2.63k | finish: |
101 | 2.63k | if (c) |
102 | 1.33k | avahi_record_unref(c); |
103 | 2.63k | if (rs) |
104 | 2.07k | avahi_record_unref(rs); |
105 | 2.63k | if (r) |
106 | 2.07k | avahi_record_unref(r); |
107 | 2.63k | if (p) |
108 | 2.63k | avahi_dns_packet_free(p); |
109 | | |
110 | 2.63k | return 0; |
111 | 1.33k | } |