| 1 |
/* |
| 2 |
* Copyright (c) 2017-2024 Free Software Foundation, Inc. |
| 3 |
* |
| 4 |
* This file is part of GNU Wget. |
| 5 |
* |
| 6 |
* GNU Wget is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU 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 |
* GNU Wget 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 General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with Wget. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <config.h> |
| 21 |
|
| 22 |
#include <sys/types.h> |
| 23 |
#include <dirent.h> // opendir, readdir |
| 24 |
#include <stdint.h> // uint8_t |
| 25 |
#include <stdio.h> // fmemopen |
| 26 |
#include <string.h> // strncmp |
| 27 |
#include <stdlib.h> // free |
| 28 |
#include <fcntl.h> // open flags |
| 29 |
#include <unistd.h> // close |
| 30 |
#include <setjmp.h> // longjmp, setjmp |
| 31 |
|
| 32 |
#include "wget.h" |
| 33 |
#undef fopen_wgetrc |
| 34 |
|
| 35 |
#ifdef __cplusplus |
| 36 |
extern "C" { |
| 37 |
#endif |
| 38 |
#include "utils.h" |
| 39 |
#include "html-url.h" |
| 40 |
#include "css-url.h" |
| 41 |
|
| 42 |
// declarations for wget internal functions |
| 43 |
int main_wget(int argc, const char **argv); |
| 44 |
void cleanup(void); |
| 45 |
FILE *fopen_wget(const char *pathname, const char *mode); |
| 46 |
FILE *fopen_wgetrc(const char *pathname, const char *mode); |
| 47 |
void exit_wget(int status); |
| 48 |
#ifdef __cplusplus |
| 49 |
} |
| 50 |
#endif |
| 51 |
|
| 52 |
#include "fuzzer.h" |
| 53 |
|
| 54 |
static const uint8_t *g_data; |
| 55 |
static size_t g_size; |
| 56 |
|
| 57 |
FILE *fopen_wget(const char *pathname, const char *mode) |
| 58 |
{ |
| 59 |
return fopen("/dev/null", mode); |
| 60 |
} |
| 61 |
|
| 62 |
FILE *fopen_wgetrc(const char *pathname, const char *mode) |
| 63 |
{ |
| 64 |
#ifdef HAVE_FMEMOPEN |
| 65 |
return fmemopen((void *) g_data, g_size, mode); |
| 66 |
#else |
| 67 |
return NULL; |
| 68 |
#endif |
| 69 |
} |
| 70 |
|
| 71 |
#ifdef FUZZING |
| 72 |
void exit_wget(int status) |
| 73 |
{ |
| 74 |
} |
| 75 |
#endif |
| 76 |
|
| 77 |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
| 78 |
{ |
| 79 |
struct urlpos *urls; |
| 80 |
struct file_memory fm; |
| 81 |
|
| 82 |
if (size > 4096) // same as max_len = ... in .options file |
| 83 |
return 0; |
| 84 |
|
| 85 |
CLOSE_STDERR |
| 86 |
|
| 87 |
fm.content = (char *) data; |
| 88 |
fm.length = size; |
| 89 |
fm.mmap_p = 0; |
| 90 |
|
| 91 |
urls = get_urls_html_fm("xxx", &fm, "https://x.y", NULL, NULL); |
| 92 |
free_urlpos(urls); |
| 93 |
|
| 94 |
RESTORE_STDERR |
| 95 |
|
| 96 |
return 0; |
| 97 |
} |