Coverage Report

Created: 2025-11-03 07:01

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