/src/avahi/fuzz/fuzz-ini-file-parser.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 <stddef.h> |
22 | | #include <stdint.h> |
23 | | #include <stdlib.h> |
24 | | #include <unistd.h> |
25 | | |
26 | | #include "avahi-common/malloc.h" |
27 | | #include "avahi-core/log.h" |
28 | | #include "avahi-daemon/ini-file-parser.h" |
29 | | |
30 | 7.86k | void log_function(AvahiLogLevel level, const char *txt) {} |
31 | | |
32 | 194 | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
33 | 194 | char name[] = "/tmp/fuzz-ini-file-parser.XXXXXX"; |
34 | 194 | int fd = -1; |
35 | 194 | ssize_t n; |
36 | 194 | AvahiIniFile *f; |
37 | 194 | AvahiIniFileGroup *g; |
38 | | |
39 | 194 | fd = mkstemp(name); |
40 | 194 | assert(fd >= 0); |
41 | | |
42 | 194 | n = write(fd, data, size); |
43 | 194 | assert(n == (ssize_t) size); |
44 | | |
45 | 194 | close(fd); |
46 | | |
47 | 194 | avahi_set_log_function(log_function); |
48 | | |
49 | 194 | if (!(f = avahi_ini_file_load(name))) |
50 | 23 | goto cleanup; |
51 | | |
52 | 171 | avahi_log_info("%u groups\n", f->n_groups); |
53 | | |
54 | 876 | for (g = f->groups; g; g = g->groups_next) { |
55 | 705 | AvahiIniFilePair *p; |
56 | 705 | avahi_log_info("<%s> (%u pairs)\n", g->name, g->n_pairs); |
57 | | |
58 | 2.00k | for (p = g->pairs; p; p = p->pairs_next) { |
59 | 1.30k | char **split, **i; |
60 | | |
61 | 1.30k | avahi_log_info("\t<%s> = ", p->key); |
62 | 1.30k | split = avahi_split_csv(p->value); |
63 | | |
64 | 5.66k | for (i = split; *i; i++) |
65 | 4.36k | avahi_log_info("<%s> ", *i); |
66 | | |
67 | 1.30k | avahi_strfreev(split); |
68 | | |
69 | 1.30k | avahi_log_info("\n"); |
70 | 1.30k | } |
71 | 705 | } |
72 | | |
73 | 194 | cleanup: |
74 | 194 | if (f) |
75 | 171 | avahi_ini_file_free(f); |
76 | 194 | unlink(name); |
77 | | |
78 | 194 | return 0; |
79 | 171 | } |