Coverage Report

Created: 2025-08-29 06:24

/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
8.62k
void log_function(AvahiLogLevel level, const char *txt) {}
30
31
966
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
32
966
    AvahiDnsPacket *p = NULL;
33
966
    AvahiKey *k1 = NULL, *k2 = NULL;
34
966
    int ret;
35
36
966
    avahi_set_log_function(log_function);
37
38
966
    if (!(p = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE)))
39
0
        goto finish;
40
41
966
    memcpy(AVAHI_DNS_PACKET_DATA(p), data, size);
42
966
    p->size = size;
43
44
966
    if (!(k1 = avahi_dns_packet_consume_key(p, NULL)))
45
356
        goto finish;
46
47
610
    ret = avahi_key_is_valid(k1);
48
610
    assert(ret);
49
50
610
    avahi_key_hash(k1);
51
52
610
    avahi_free(avahi_key_to_string(k1));
53
54
610
    if ((k2 = avahi_key_new_cname(k1)))
55
77
        avahi_key_unref(k2);
56
57
610
    if (!(k2 = avahi_dns_packet_consume_key(p, NULL)))
58
280
        goto finish;
59
60
330
    ret = avahi_key_is_valid(k2);
61
330
    assert(ret);
62
63
330
    if (!avahi_key_is_pattern(k2))
64
325
        avahi_key_pattern_match(k1, k2);
65
66
966
finish:
67
966
    if (k2)
68
330
        avahi_key_unref(k2);
69
966
    if (k1)
70
610
        avahi_key_unref(k1);
71
966
    if (p)
72
966
        avahi_dns_packet_free(p);
73
74
966
    return 0;
75
330
}