Coverage Report

Created: 2026-06-30 06:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/avahi/fuzz/fuzz-consume-record.c
Line
Count
Source
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
#ifdef HAVE_NALLOCFUZZ
29
#include "nallocinc.c"
30
#endif
31
32
7.44k
void log_function(AvahiLogLevel level, const char *txt) {}
33
34
0
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
35
0
    AvahiDnsPacket *p = NULL;
36
0
    AvahiRecord *r = NULL, *rs = NULL, *c = NULL;
37
0
    uint8_t rdata[AVAHI_DNS_RDATA_MAX];
38
0
    size_t rdata_size;
39
0
    int ret;
40
41
0
    avahi_set_log_function(log_function);
42
43
0
    if (!(p = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE)))
44
0
        goto finish;
45
46
0
    memcpy(AVAHI_DNS_PACKET_DATA(p), data, size);
47
0
    p->size = size;
48
49
#ifdef HAVE_NALLOCFUZZ
50
    nalloc_start(data, size);
51
#endif
52
53
0
    if (!(r = avahi_dns_packet_consume_record(p, NULL)))
54
0
        goto finish;
55
56
0
    ret = avahi_record_is_valid(r);
57
0
    assert(ret);
58
59
0
    avahi_record_is_goodbye(r);
60
61
0
    avahi_record_is_link_local_address(r);
62
63
0
    avahi_record_get_estimate_size(r);
64
65
0
    avahi_free(avahi_record_to_string(r));
66
67
0
    rdata_size = avahi_rdata_serialize(r, rdata, sizeof(rdata));
68
#ifdef HAVE_NALLOCFUZZ
69
    if (rdata_size == (size_t) -1)
70
        goto finish;
71
#endif
72
0
    assert(rdata_size != (size_t) -1);
73
74
0
    if (!(rs = avahi_record_new_full(r->key->name, r->key->clazz, r->key->type, r->ttl)))
75
0
        goto finish;
76
77
0
    if (avahi_rdata_parse(rs, rdata, rdata_size) < 0)
78
0
        goto finish;
79
80
0
    ret = avahi_record_is_valid(rs);
81
0
    assert(ret);
82
83
0
    ret = avahi_record_equal_no_ttl(r, rs);
84
0
    assert(ret);
85
86
0
    ret = avahi_record_lexicographical_compare(r, rs);
87
0
#ifndef HAVE_NALLOCFUZZ
88
0
    assert(ret == 0);
89
0
#endif
90
91
0
    if (!(c = avahi_record_copy(r)))
92
0
        goto finish;
93
94
0
    ret = avahi_record_equal_no_ttl(r, c);
95
0
    assert(ret);
96
97
0
    ret = avahi_record_lexicographical_compare(r, c);
98
0
#ifndef HAVE_NALLOCFUZZ
99
0
    assert(ret == 0);
100
0
#endif
101
102
0
    avahi_record_unref(c);
103
0
    if (!(c = avahi_dns_packet_consume_record(p, NULL)))
104
0
        goto finish;
105
106
0
    avahi_record_equal_no_ttl(r, c);
107
0
    avahi_record_lexicographical_compare(r, c);
108
109
0
    avahi_dns_packet_free(p);
110
0
    if (!(p = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE)))
111
0
        goto finish;
112
113
0
    if (!avahi_dns_packet_append_record(p, r, 0, 0))
114
0
        goto finish;
115
116
0
finish:
117
0
    if (c)
118
0
        avahi_record_unref(c);
119
0
    if (rs)
120
0
        avahi_record_unref(rs);
121
0
    if (r)
122
0
        avahi_record_unref(r);
123
0
    if (p)
124
0
        avahi_dns_packet_free(p);
125
126
#ifdef HAVE_NALLOCFUZZ
127
    nalloc_end();
128
#endif
129
130
0
    return 0;
131
0
}