/src/wget2/fuzz/libwget_http_parse_fuzzer.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright (c) 2017-2026 Free Software Foundation, Inc. |
3 | | * |
4 | | * This file is part of libwget. |
5 | | * |
6 | | * Libwget is free software: you can redistribute it and/or modify |
7 | | * it under the terms of the GNU Lesser General Public License as published by |
8 | | * the Free Software Foundation, either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * Libwget is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU Lesser General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU Lesser General Public License |
17 | | * along with libwget. If not, see <https://www.gnu.org/licenses/>. |
18 | | */ |
19 | | |
20 | | #include <config.h> |
21 | | |
22 | | #include <assert.h> |
23 | | #include <stdio.h> |
24 | | #include <stdint.h> |
25 | | #include <stdlib.h> |
26 | | #include <string.h> |
27 | | |
28 | | #include "wget.h" |
29 | | #include "fuzzer.h" |
30 | | |
31 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
32 | 18.7k | { |
33 | 18.7k | if (size > 4096) // same as max_len = 10000 in .options file |
34 | 38 | return 0; |
35 | | |
36 | 18.7k | char *in = (char *) malloc(size + 1); |
37 | 18.7k | assert(in != NULL); |
38 | | |
39 | | // 0 terminate |
40 | 18.7k | memcpy(in, data, size); |
41 | 18.7k | in[size] = 0; |
42 | | |
43 | 18.7k | wget_http_response *resp = wget_http_parse_response_header(in); |
44 | 18.7k | wget_http_free_response(&resp); |
45 | | |
46 | 18.7k | free(in); |
47 | | |
48 | 18.7k | return 0; |
49 | 18.7k | } |