1
0
mirror of https://github.com/mirror/wget.git synced 2025-04-14 21:40:42 +08:00

Add new fuzzer wget_read_hunk_fuzzer.c

* fuzz/Makefile.am: Add wget_read_hunk_fuzzer
* fuzz/wget_read_hunk_fuzzer.c: New file
* fuzz/wget_read_hunk_fuzzer.in/*: Fuzz corpora
* src/connect.c: Add connect_cleanup()
* src/connect.h: Add prototype for connect_cleanup()
This commit is contained in:
Tim Rühsen 2019-03-25 14:57:00 +01:00
parent ae6636a28f
commit 4046cd2a71
175 changed files with 309 additions and 1 deletions
fuzz
Makefile.amwget_read_hunk_fuzzer.c
wget_read_hunk_fuzzer.in
003e6d143ff987e57e308a247a43e990aa485cd70181b09bdeaf9ac0c465d0916ccc0f809ad000dc0223d9b49784338193078cc1ce4937d1ae0843ee03324eed2a844c2c712c3a736395dd996ff5da3a04547ff005a6f7595221d0f1dbc32dcfecb6f78204a822e65bb1e8bb2c19f09b187004bb3f8b165006f4cdeb821523a02351795dc305b330196dd95e09543c8214d579ab15c96c09267a61c8aaf8c9ef0cf306ab7b608c5fa2237f5f6074413678bb4d300d6f426a1b95acb9a942724b3fded6adc95365490e3db6c438a6d2126102efdfdd9d7485d2a985d11039afa8afb460eb2a2da45cd39131e93b5dd5ae15028bb41ce09cb0e6386a448a17b404618d2c6d15c59fa0420280649a7844b6298b961865efdd76173e71af110ef79a98a40adf5e245805b5c746e3179a1d6f629fea76cce60cc511e5a40dff488e5c1810663830552bc36933d8e645382f8b3266ca5b18ff2ae9f881796980f082dfb217b34553160cb11bd20951b918e0434eb1cd420543bc79e68502991cb6cfc92ef9ac81689051c41fdca87c8cdb718a200e3883469d4d99b28d29167bf9a48d33efcf5b21d221503e5b3cba697744ebef723c90a107345d223e49ca36b549c406edaee2b04a68bdb2baeb0822cb4d7ce76fa008fa4927238f2a87dc4e10a41725db0570cd4eeeafb131bd3698f4c544f40017e12814fab44162c18a29148cb0b5e40271fdf9b0312a4630b84731f6f7ae444a86c0f1026faca44d822bcb1b518040217690b627761d4f5c904bf437d82d9951d3e0125ba6933c7131b4f3890aa6a23bed35cc83ddacfa942592c1f8ca25f2889772739b5c368482788b29bd18fcbfa4b93548f08429897eb836b093624fe06ad4840d65745d25543fcb11d97038c198dcaaba1c1d5d3e3a02d9655ae82f0ca4143ba332ad784e2a2db3ba1ab7bd3e0050a6c068913c84550f8813be57a085bffc4b2cb62c5869afff3da72e604871236487499a2669c0edd6e462d5433ee89b3f85ff5fc29c167a2c790d5095cdef05de40a50e5bfeaf182fb9def6c12891c11f4259f81b40ad455c1a1135683554efb7f9bb09c27f111b2b468901f2e421aa43c4fd4483f7e0136b02934380473f27bfddad19ca56ad323552da11e65a9caa264a2b7413690de2c27f3379006ed7984a5405ae744be65cad5fe09b77a2eb600fbf235689c9d7fb734c93a532486c2f5736dcba17309daf0f663158214d863d2fe3f74e61c4d38ecb7bf1d992d9e7e7ea4dbe2f639ae782ad317f578f150d8960d5d457984dfdf03a30b2aa1fb08a74050432d50c14564fe94e03b436ff693e29671e15ce8e0d2215253614ab4f45e52e8be9ebcc39142cfd4721eedf5667d0d7512db50c6349d05338790c5d1061dd746928d3bd53bc74268c5abb817710fba5b132941743cd0bc458689eb90af0ed17fae9466f6060bfe7eb9fc43a5b7b287da8a4b21a8f0dbb277a62cd2a6e2f15015c16c7cf49a5f8e19b8a1661b9964ad0223aba945f0d46f5aad7b212568b4db72743ca9c22f134fc62f7ed0ff0ee4f3796fcc1c0ee583546942f393863451c9bbffc0dc2d1b6b2cd83b039ad73a4aad4637987455cb6d18a2bc4b087c58870f39a8ab7ca6488c43f6fe79f21e2a629a6e74bc8cbb04b528864c38cf29a15ea03a3844b4bbabeaa53f7a42d2864eda710031b3c2801eb8382041831681f4162d26744fcec5fb226642656cce84ee2f3d048240d9d6752c6fdef5062eeb34c489f22c9350fe8801afe67f8a9bbb52115e20e58aa835e12541452c672746803c7076b741c8bf324424472c4fd06ef1004656837896608e80848e5b6b1df5da5e05d484a616a693be1c75e5eed87ae4357f32af905cab90529f269b9406ef2e3a8c093555bc74090136aa24792c16c33875747eca81c5b2474d3d16a1255992ef1266d528a0c51d29738948554967691cdc7969571226de204bb4d00a006939c4d44c9573ea51dc818a16e1075c0489eab6cc8eb88e9538018a3599f2e556e9d782602823122977bd6988b95da85eedc87486f6ec37a2a81b9fc3288a801abe85b71f87aa9a96f9d233b734e799ad751e5246f92b397250391d371783c091bd4f8235429ad265437aca75d4ebae572251b17b8ee58f7688816c80eee9b0188551cf574df3cac22da752fc21cfb4b01c10b1b35e3943a75b29523dab353ea16ace78661833f0bb8874aa476f7768231655eba466f04bea6944309a8b9531d7862f2e8dabc17d4047bd225d366ed114496248878644d44a6277159bf71d8a97ec6c5a2ed6f679378fa8a53a78994a5690e46885a3553b33cd7afc980bfe133b08cabda0426de4a5f3bb02527f4959f8159742cbdaf7a6da35ccd92c17ccbfcde6226048227de5777e589e0730bf1d7b72992433c5b309e82ca7a52d589e9dbae37ebf1c59fac7ad876eb7c83f357a488921bc823e67087488baddc4c649ace849addb5c16ac03eda9d577939047f8a5135768c84bebdf686ec8242f1e039cf034ac2880a1c69858626fd796c662c653271519258a41cde9a1c171c87f636c13a8eab70dd3098448e1f1cccef596614897eab39bbb189e8ab365c70721693014a50458a8cdfd91f8eb4d0876e11de77e4513014c0d08e6a8d453419bad515e54fb34569202881cb575982d58d92aafef4a337e69780be13371de1f8e04bbb618fb00477112b8228f40b0ba5f697dfce5fa3ddaa8fc1c7770a1425b6de0e8ad0a362d15ecad197a5

View File

@ -16,7 +16,8 @@ WGET_TESTS = \
wget_netrc_fuzzer$(EXEEXT) \
wget_options_fuzzer$(EXEEXT) \
wget_robots_fuzzer$(EXEEXT) \
wget_url_fuzzer$(EXEEXT)
wget_url_fuzzer$(EXEEXT) \
wget_read_hunk_fuzzer$(EXEEXT)
if FUZZING
bin_PROGRAMS = $(WGET_TESTS)
@ -60,6 +61,9 @@ wget_robots_fuzzer_LDADD = ../src/libunittest.a $(LDADD)
wget_url_fuzzer_SOURCES = wget_url_fuzzer.c $(MAIN)
wget_url_fuzzer_LDADD = ../src/libunittest.a $(LDADD)
wget_read_hunk_fuzzer_SOURCES = wget_read_hunk_fuzzer.c $(MAIN)
wget_read_hunk_fuzzer_LDADD = ../src/libunittest.a $(LDADD)
#EXTRA_DIST = $(wildcard *.options) $(wildcard *.dict) \
# $(wildcard *.in) $(wildcard *.repro)

View File

@ -0,0 +1,204 @@
/*
* Copyright (c) 2019 Free Software Foundation, Inc.
*
* This file is part of GNU Wget.
*
* GNU Wget is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* GNU Wget is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Wget. If not, see <https://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <sys/types.h>
#include <stdint.h> // uint8_t
#include <stdio.h> // fmemopen
#include <string.h> // strncmp
#include <stdlib.h> // free
#include <unistd.h> // close
#include <fcntl.h> // open flags
#include <unistd.h> // close
#include <unistd.h> // close
#include "wget.h"
#include "connect.h"
#undef fopen_wgetrc
#ifdef __cplusplus
extern "C" {
#endif
#include "retr.h"
// declarations for wget internal functions
int main_wget(int argc, const char **argv);
void cleanup(void);
// FILE *fopen_wget(const char *pathname, const char *mode);
// FILE *fopen_wgetrc(const char *pathname, const char *mode);
void exit_wget(int status);
#ifdef __cplusplus
}
#endif
#include "fuzzer.h"
FILE *fopen_wget(const char *pathname, const char *mode)
{
return fopen("/dev/null", mode);
}
FILE *fopen_wgetrc(const char *pathname, const char *mode)
{
return NULL;
}
#ifdef FUZZING
void exit_wget(int status)
{
}
#endif
static const uint8_t *g_data;
static size_t g_size, g_read;
struct my_context {
int peeklen;
char peekbuf[512];
};
static int my_peek (int fd _GL_UNUSED, char *buf, int bufsize, void *arg)
{
if (g_read < g_size) {
struct my_context *ctx = (struct my_context *) arg;
int n = rand() % (g_size - g_read);
if (n > bufsize)
n = bufsize;
if (n > sizeof(ctx->peekbuf))
n = sizeof(ctx->peekbuf);
memcpy(buf, g_data + g_read, n);
memcpy(ctx->peekbuf, g_data + g_read, n);
g_read += n;
ctx->peeklen=n;
return n;
}
return 0;
}
static int my_read (int fd _GL_UNUSED, char *buf, int bufsize, void *arg)
{
struct my_context *ctx = (struct my_context *) arg;
if (ctx->peeklen) {
/* If we have any peek data, simply return that. */
int copysize = MIN (bufsize, ctx->peeklen);
memcpy (buf, ctx->peekbuf, copysize);
ctx->peeklen -= copysize;
if (ctx->peeklen)
memmove (ctx->peekbuf, ctx->peekbuf + copysize, ctx->peeklen);
return copysize;
}
if (g_read < g_size) {
int n = rand() % (g_size - g_read);
if (n > bufsize)
n = bufsize;
memcpy(buf, g_data + g_read, n);
g_read += n;
return n;
}
return 0;
}
static int my_write (int fd _GL_UNUSED, char *buf _GL_UNUSED, int bufsize, void *arg _GL_UNUSED)
{
return bufsize;
}
static int my_poll (int fd _GL_UNUSED, double timeout _GL_UNUSED, int wait_for _GL_UNUSED, void *arg)
{
struct my_context *ctx = (struct my_context *) arg;
return ctx->peeklen || g_read < g_size;
}
static const char *my_errstr (int fd _GL_UNUSED, void *arg _GL_UNUSED)
{
return "Success";
}
static void my_close (int fd _GL_UNUSED, void *arg _GL_UNUSED)
{
}
static struct transport_implementation my_transport =
{
my_read, my_write, my_poll,
my_peek, my_errstr, my_close
};
/* copied from wget's http.c */
static const char *
response_head_terminator (const char *start, const char *peeked, int peeklen)
{
const char *p, *end;
/* If at first peek, verify whether HUNK starts with "HTTP". If
not, this is a HTTP/0.9 request and we must bail out without
reading anything. */
if (start == peeked && 0 != memcmp (start, "HTTP", MIN (peeklen, 4)))
return start;
/* Look for "\n[\r]\n", and return the following position if found.
Start two chars before the current to cover the possibility that
part of the terminator (e.g. "\n\r") arrived in the previous
batch. */
p = peeked - start < 2 ? start : peeked - 2;
end = peeked + peeklen;
/* Check for \n\r\n or \n\n anywhere in [p, end-2). */
for (; p < end - 2; p++)
if (*p == '\n')
{
if (p[1] == '\r' && p[2] == '\n')
return p + 3;
else if (p[1] == '\n')
return p + 2;
}
/* p==end-2: check for \n\n directly preceding END. */
if (p[0] == '\n' && p[1] == '\n')
return p + 2;
return NULL;
}
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
char *hunk;
if (size > 4096) // same as max_len = ... in .options file
return 0;
// CLOSE_STDERR
g_data = data;
g_size = size;
g_read = 0;
struct my_context *ctx = calloc(1, sizeof(struct my_context));
fd_register_transport(99, &my_transport, ctx);
while ((hunk = fd_read_hunk(99, response_head_terminator, 512, 65536)))
free(hunk);
connect_cleanup();
free(ctx);
// RESTORE_STDERR
return 0;
}

View File

@ -0,0 +1,3 @@
HTTP
'

View File

@ -0,0 +1,2 @@
HTTP
<EFBFBD>

View File

@ -0,0 +1,5 @@
HTTPHH~:þ±
QHTTPHH~:þ±
QTT)÷)÷ÿ

View File

@ -0,0 +1,3 @@
H
<EFBFBD>

View File

@ -0,0 +1 @@
HTTP<EFBFBD><EFBFBD>)<29>M<EFBFBD><4D>

View File

@ -0,0 +1 @@
HTTP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD>HTTP<54><50>

View File

@ -0,0 +1 @@
H!T'<27>

View File

@ -0,0 +1 @@
HTT~~~

View File

@ -0,0 +1,3 @@
HTTPH
<EFBFBD>
~

View File

@ -0,0 +1,2 @@
HTTH
:

View File

@ -0,0 +1 @@
'!<21><>!

View File

@ -0,0 +1 @@
HTTPHHH

View File

@ -0,0 +1,4 @@
HTP
H
ォス

View File

@ -0,0 +1,3 @@
HTTP<EFBFBD>
<EFBFBD>

View File

@ -0,0 +1 @@
HTH<EFBFBD>

View File

@ -0,0 +1 @@
HT HHT

View File

@ -0,0 +1,5 @@
HTTP
HTTP
'

View File

@ -0,0 +1,3 @@
HT
Q

View File

@ -0,0 +1,5 @@
HTTP77737
HTTP
'

Some files were not shown because too many files have changed in this diff Show More