Coverage Report

Created: 2025-08-26 06:42

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