1 /*
2 * Copyright (c) 2017-2021 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> // assert
23 #include <stdlib.h> // malloc, free
24 #include <string.h> // memcpy
25
26 #include "wget.h"
27 #include "fuzzer.h"
28
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)29 int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
30 {
31 int x = 0; // avoid pure functions to be optimized away
32
33 if (size > 100) // same as max_len = 100 in .options file
34 return 0;
35
36 char *in = (char *)malloc(size + 1);
37
38 assert(in != NULL);
39
40 // 0 terminate
41 memcpy(in, data, size);
42 in[size] = 0;
43
44 if (wget_base64_is_string(NULL) || wget_base64_is_string(in))
45 in[size] = 0;
46
47 wget_free(wget_base64_decode_alloc((char *) data, size, NULL));
48 wget_free(wget_base64_encode_printf_alloc("%s", in));
49
50 free(in);
51
52 x += wget_base64_get_decoded_length(5);
53 x += wget_base64_get_encoded_length(5);
54
55 (void) x; // needed to get rid of bug reported by scan-build
56
57 return 0;
58 }
59