Coverage Report

Created: 2025-07-01 06:05

/src/avahi/fuzz/fuzz-strlst.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 <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
29
410
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
30
410
    AvahiStringList *a = NULL, *b = NULL;
31
410
    uint8_t *rdata = NULL;
32
410
    char *t = NULL;
33
410
    size_t s, n;
34
410
    int ret;
35
36
410
    if (avahi_string_list_parse(data, size, &a) < 0)
37
39
        goto finish;
38
39
371
    if ((t = avahi_string_list_to_string(a)))
40
371
        assert(avahi_utf8_valid(t));
41
42
371
    avahi_free(avahi_string_list_to_string(a));
43
371
    avahi_string_list_get_service_cookie(a);
44
45
371
    n = avahi_string_list_serialize(a, NULL, 0);
46
371
    assert(n > 0);
47
371
    if (!(rdata = avahi_malloc(n)))
48
0
        goto finish;
49
50
371
    s = avahi_string_list_serialize(a, rdata, n);
51
371
    assert(s == n);
52
53
371
    if (avahi_string_list_parse(rdata, n, &b) < 0)
54
0
        goto finish;
55
56
371
    ret = avahi_string_list_equal(a, b);
57
371
    assert(ret);
58
59
371
    avahi_string_list_free(b);
60
371
    if (!(b = avahi_string_list_copy(a)))
61
8
        goto finish;
62
63
363
    ret = avahi_string_list_equal(a, b);
64
363
    assert(ret);
65
66
410
finish:
67
410
    avahi_free(t);
68
410
    avahi_free(rdata);
69
410
    if (b)
70
363
        avahi_string_list_free(b);
71
410
    if (a)
72
363
        avahi_string_list_free(a);
73
74
410
    return 0;
75
363
}