Coverage Report

Created: 2026-02-12 07:07

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