Coverage Report

Created: 2023-06-07 06:18

/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/log.h"
26
27
118
void log_function(AvahiLogLevel level, const char *txt) {}
28
29
1.96k
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
30
1.96k
    avahi_set_log_function(log_function);
31
1.96k
    AvahiDnsPacket* packet = avahi_dns_packet_new(size + AVAHI_DNS_PACKET_EXTRA_SIZE);
32
1.96k
    memcpy(AVAHI_DNS_PACKET_DATA(packet), data, size);
33
1.96k
    packet->size = size;
34
1.96k
    AvahiKey* key = avahi_dns_packet_consume_key(packet, NULL);
35
1.96k
    if (key) {
36
736
        avahi_key_is_valid(key);
37
736
        char *s = avahi_key_to_string(key);
38
736
        avahi_free(s);
39
736
        avahi_key_unref(key);
40
736
    }
41
1.96k
    avahi_dns_packet_free(packet);
42
43
1.96k
    return 0;
44
1.96k
}