Coverage Report

Created: 2026-04-09 06:50

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
8.74k
void log_function(AvahiLogLevel level, const char *txt) {}
29
30
2.84k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
31
2.84k
    AvahiDnsPacket *p = NULL;
32
2.84k
    AvahiRecord *r = NULL, *rs = NULL, *c = NULL;
33
2.84k
    uint8_t rdata[AVAHI_DNS_RDATA_MAX];
34
2.84k
    size_t rdata_size;
35
2.84k
    int ret;
36
37
2.84k
    avahi_set_log_function(log_function);
38
39
2.84k
    if (!(p = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE)))
40
0
        goto finish;
41
42
2.84k
    memcpy(AVAHI_DNS_PACKET_DATA(p), data, size);
43
2.84k
    p->size = size;
44
45
2.84k
    if (!(r = avahi_dns_packet_consume_record(p, NULL)))
46
561
        goto finish;
47
48
2.28k
    ret = avahi_record_is_valid(r);
49
2.28k
    assert(ret);
50
51
2.28k
    avahi_record_is_goodbye(r);
52
53
2.28k
    avahi_record_is_link_local_address(r);
54
55
2.28k
    avahi_record_get_estimate_size(r);
56
57
2.28k
    avahi_free(avahi_record_to_string(r));
58
59
2.28k
    rdata_size = avahi_rdata_serialize(r, rdata, sizeof(rdata));
60
2.28k
    assert(rdata_size != (size_t) -1);
61
62
2.28k
    if (!(rs = avahi_record_new_full(r->key->name, r->key->clazz, r->key->type, r->ttl)))
63
0
        goto finish;
64
65
2.28k
    if (avahi_rdata_parse(rs, rdata, rdata_size) < 0)
66
0
        goto finish;
67
68
2.28k
    ret = avahi_record_is_valid(rs);
69
2.28k
    assert(ret);
70
71
2.28k
    ret = avahi_record_equal_no_ttl(r, rs);
72
2.28k
    assert(ret);
73
74
2.28k
    ret = avahi_record_lexicographical_compare(r, rs);
75
2.28k
    assert(ret == 0);
76
77
2.28k
    if (!(c = avahi_record_copy(r)))
78
0
        goto finish;
79
80
2.28k
    ret = avahi_record_equal_no_ttl(r, c);
81
2.28k
    assert(ret);
82
83
2.28k
    ret = avahi_record_lexicographical_compare(r, c);
84
2.28k
    assert(ret == 0);
85
86
2.28k
    avahi_record_unref(c);
87
2.28k
    if (!(c = avahi_dns_packet_consume_record(p, NULL)))
88
802
        goto finish;
89
90
1.48k
    avahi_record_equal_no_ttl(r, c);
91
1.48k
    avahi_record_lexicographical_compare(r, c);
92
93
1.48k
    avahi_dns_packet_free(p);
94
1.48k
    if (!(p = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE)))
95
0
        goto finish;
96
97
1.48k
    if (!avahi_dns_packet_append_record(p, r, 0, 0))
98
143
        goto finish;
99
100
2.84k
finish:
101
2.84k
    if (c)
102
1.48k
        avahi_record_unref(c);
103
2.84k
    if (rs)
104
2.28k
        avahi_record_unref(rs);
105
2.84k
    if (r)
106
2.28k
        avahi_record_unref(r);
107
2.84k
    if (p)
108
2.84k
        avahi_dns_packet_free(p);
109
110
2.84k
    return 0;
111
1.48k
}