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-key.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/domain-util.h"
26
#include "avahi-core/log.h"
27
#include "avahi-core/rr-util.h"
28
29
#ifdef HAVE_NALLOCFUZZ
30
#include "nallocinc.c"
31
#endif
32
33
7.44k
void log_function(AvahiLogLevel level, const char *txt) {}
34
35
0
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
36
0
    AvahiDnsPacket *p = NULL;
37
0
    AvahiKey *k1 = NULL, *k2 = NULL;
38
0
    int ret;
39
40
0
    avahi_set_log_function(log_function);
41
42
0
    if (!(p = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE)))
43
0
        goto finish;
44
45
0
    memcpy(AVAHI_DNS_PACKET_DATA(p), data, size);
46
0
    p->size = size;
47
48
#ifdef HAVE_NALLOCFUZZ
49
    nalloc_start(data, size);
50
#endif
51
52
0
    if (!(k1 = avahi_dns_packet_consume_key(p, NULL)))
53
0
        goto finish;
54
55
0
    ret = avahi_key_is_valid(k1);
56
0
    assert(ret);
57
58
0
    avahi_key_hash(k1);
59
60
0
    avahi_free(avahi_key_to_string(k1));
61
62
0
    if ((k2 = avahi_key_new_cname(k1)))
63
0
        avahi_key_unref(k2);
64
65
0
    if (!(k2 = avahi_dns_packet_consume_key(p, NULL)))
66
0
        goto finish;
67
68
0
    ret = avahi_key_is_valid(k2);
69
0
    assert(ret);
70
71
0
    if (!avahi_key_is_pattern(k2))
72
0
        avahi_key_pattern_match(k1, k2);
73
74
0
finish:
75
0
    if (k2)
76
0
        avahi_key_unref(k2);
77
0
    if (k1)
78
0
        avahi_key_unref(k1);
79
0
    if (p)
80
0
        avahi_dns_packet_free(p);
81
82
#ifdef HAVE_NALLOCFUZZ
83
    nalloc_end();
84
#endif
85
86
0
    return 0;
87
0
}