mirror of
https://github.com/mirror/wget.git
synced 2025-01-27 04:40:41 +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:
parent
ae6636a28f
commit
4046cd2a71
@ -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)
|
||||
|
||||
|
204
fuzz/wget_read_hunk_fuzzer.c
Normal file
204
fuzz/wget_read_hunk_fuzzer.c
Normal 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;
|
||||
}
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
HTTP
|
||||
|
||||
'
|
@ -0,0 +1,2 @@
|
||||
HTTP
|
||||
<EFBFBD>
|
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
HTTPHH~:þ±
|
||||
|
||||
QHTTPHH~:þ±
|
||||
|
||||
QTT)÷)÷ÿ
|
@ -0,0 +1,3 @@
|
||||
H
|
||||
|
||||
<EFBFBD>
|
@ -0,0 +1 @@
|
||||
HTTP<EFBFBD><EFBFBD>)<29>M<EFBFBD><4D>
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
HTTP<EFBFBD><EFBFBD><EFBFBD><EFBFBD>)<29><><EFBFBD><EFBFBD><EFBFBD>HTTP<54><50>
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
HHT
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
H!T'<27>
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
HTT~~~
|
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
HTTPH
|
||||
<EFBFBD>
|
||||
~
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
HHH;
|
@ -0,0 +1,2 @@
|
||||
HTTH
|
||||
:
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
'!<21><>!
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
HTTPHHH
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
HIHHT
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,4 @@
|
||||
HTP
|
||||
|
||||
H
|
||||
ォス
|
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
H
|
||||
|
||||
T
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,3 @@
|
||||
HTTP<EFBFBD>
|
||||
|
||||
<EFBFBD>
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
HT
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
HTH
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
HHHT
|
Binary file not shown.
@ -0,0 +1,2 @@
|
||||
tk
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1 @@
|
||||
HTH<EFBFBD>
|
@ -0,0 +1 @@
|
||||
HT HHT
|
Binary file not shown.
@ -0,0 +1 @@
|
||||
HTT
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
HTTP
|
||||
|
||||
HTTP
|
||||
|
||||
'
|
@ -0,0 +1,3 @@
|
||||
HT
|
||||
|
||||
Q
|
Binary file not shown.
@ -0,0 +1,5 @@
|
||||
HTTP77737
|
||||
|
||||
HTTP
|
||||
|
||||
'
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user