Coverage Report

Created: 2026-12-01 06:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/avahi/fuzz/fuzz-strlst.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 <assert.h>
21
#include <stdint.h>
22
#include <stddef.h>
23
24
#include "avahi-common/malloc.h"
25
#include "avahi-common/strlst.h"
26
#include "avahi-common/utf8.h"
27
28
#ifdef HAVE_NALLOCFUZZ
29
#include "nallocinc.c"
30
#endif
31
32
407
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
407
    AvahiStringList *a = NULL, *b = NULL;
34
407
    uint8_t *rdata = NULL;
35
407
    char *t = NULL;
36
407
    size_t s, n;
37
407
    int ret;
38
39
#ifdef HAVE_NALLOCFUZZ
40
    nalloc_start(data, size);
41
#endif
42
43
407
    if (avahi_string_list_parse(data, size, &a) < 0)
44
35
        goto finish;
45
46
372
    if ((t = avahi_string_list_to_string(a)))
47
372
        assert(avahi_utf8_valid(t));
48
49
372
    avahi_free(avahi_string_list_to_string(a));
50
372
    avahi_string_list_get_service_cookie(a);
51
52
372
    n = avahi_string_list_serialize(a, NULL, 0);
53
372
    assert(n > 0);
54
372
    if (!(rdata = avahi_malloc(n)))
55
0
        goto finish;
56
57
372
    s = avahi_string_list_serialize(a, rdata, n);
58
372
    assert(s == n);
59
60
372
    if (avahi_string_list_parse(rdata, n, &b) < 0)
61
0
        goto finish;
62
63
372
    ret = avahi_string_list_equal(a, b);
64
372
    assert(ret);
65
66
372
    avahi_string_list_free(b);
67
372
    if (!(b = avahi_string_list_copy(a)))
68
7
        goto finish;
69
70
365
    ret = avahi_string_list_equal(a, b);
71
365
    assert(ret);
72
73
407
finish:
74
407
    avahi_free(t);
75
407
    avahi_free(rdata);
76
407
    if (b)
77
365
        avahi_string_list_free(b);
78
407
    if (a)
79
365
        avahi_string_list_free(a);
80
81
#ifdef HAVE_NALLOCFUZZ
82
    nalloc_end();
83
#endif
84
85
407
    return 0;
86
365
}