* Merged chars.c and fuzz.c.
This commit is contained in:
+2
-2
@@ -1,12 +1,12 @@
|
||||
|
||||
bin_PROGRAMS = zzuf
|
||||
zzuf_SOURCES = zzuf.c random.c random.h chars.c chars.h fd.c fd.h fuzz.c fuzz.h
|
||||
zzuf_SOURCES = zzuf.c random.c random.h fd.c fd.h fuzz.c fuzz.h
|
||||
zzuf_CFLAGS = -DLIBDIR=\"$(libdir)/zzuf\"
|
||||
|
||||
pkglib_LTLIBRARIES = libzzuf.la
|
||||
libzzuf_la_SOURCES = libzzuf.c libzzuf.h fuzz.c fuzz.h debug.c debug.h \
|
||||
load-fd.c load-signal.c load-stream.c load.h \
|
||||
fd.c fd.h chars.c chars.h random.c random.h
|
||||
fd.c fd.h random.c random.h
|
||||
libzzuf_la_LDFLAGS = -avoid-version -no-undefined
|
||||
libzzuf_la_LIBADD = @GETOPT_LIBS@ @DL_LIBS@
|
||||
|
||||
|
||||
-96
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* zzuf - general purpose fuzzer
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* chars.c: protected/refused characters
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if defined HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#elif defined HAVE_INTTYPES_H
|
||||
# include <inttypes.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#include "libzzuf.h"
|
||||
#include "chars.h"
|
||||
|
||||
void _zz_readchars(int *table, char const *list)
|
||||
{
|
||||
static char const hex[] = "0123456789abcdef0123456789ABCDEF";
|
||||
char const *tmp;
|
||||
int a, b;
|
||||
|
||||
memset(table, 0, 256 * sizeof(int));
|
||||
|
||||
for(tmp = list, a = b = -1; *tmp; tmp++)
|
||||
{
|
||||
int new;
|
||||
|
||||
if(*tmp == '\\' && tmp[1] == '\0')
|
||||
new = '\\';
|
||||
else if(*tmp == '\\')
|
||||
{
|
||||
tmp++;
|
||||
if(*tmp == 'n')
|
||||
new = '\n';
|
||||
else if(*tmp == 'r')
|
||||
new = '\r';
|
||||
else if(*tmp == 't')
|
||||
new = '\t';
|
||||
else if(tmp[0] >= '0' && tmp[0] <= '7' && tmp[1] >= '0'
|
||||
&& tmp[1] <= '7' && tmp[2] >= '0' && tmp[2] <= '7')
|
||||
{
|
||||
new = tmp[2] - '0';
|
||||
new |= (int)(tmp[1] - '0') << 3;
|
||||
new |= (int)(tmp[0] - '0') << 6;
|
||||
tmp += 2;
|
||||
}
|
||||
else if((*tmp == 'x' || *tmp == 'X')
|
||||
&& tmp[1] && strchr(hex, tmp[1])
|
||||
&& tmp[2] && strchr(hex, tmp[2]))
|
||||
{
|
||||
new = ((strchr(hex, tmp[1]) - hex) & 0xf) << 4;
|
||||
new |= (strchr(hex, tmp[2]) - hex) & 0xf;
|
||||
tmp += 2;
|
||||
}
|
||||
else
|
||||
new = (unsigned char)*tmp; /* XXX: OK for \\, but what else? */
|
||||
}
|
||||
else
|
||||
new = (unsigned char)*tmp;
|
||||
|
||||
if(a != -1 && b == '-' && a <= new)
|
||||
{
|
||||
while(a <= new)
|
||||
table[a++] = 1;
|
||||
a = b = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(a != -1)
|
||||
table[a] = 1;
|
||||
a = b;
|
||||
b = new;
|
||||
}
|
||||
}
|
||||
|
||||
if(a != -1)
|
||||
table[a] = 1;
|
||||
if(b != -1)
|
||||
table[b] = 1;
|
||||
}
|
||||
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
/*
|
||||
* zzuf - general purpose fuzzer
|
||||
* Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
|
||||
* All Rights Reserved
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* This program is free software. It comes without any warranty, to
|
||||
* the extent permitted by applicable law. You can redistribute it
|
||||
* and/or modify it under the terms of the Do What The Fuck You Want
|
||||
* To Public License, Version 2, as published by Sam Hocevar. See
|
||||
* http://sam.zoy.org/wtfpl/COPYING for more details.
|
||||
*/
|
||||
|
||||
/*
|
||||
* chars.h: character functions
|
||||
*/
|
||||
|
||||
extern void _zz_readchars(int *, char const *);
|
||||
|
||||
+97
-16
@@ -36,21 +36,36 @@
|
||||
#define MAGIC1 0x33ea84f7
|
||||
#define MAGIC2 0x783bc31f
|
||||
|
||||
static float _zz_ratio = 0.004f;
|
||||
static int _zz_seed = 0;
|
||||
/* Fuzzing variables */
|
||||
static int protect[256];
|
||||
static int refuse[256];
|
||||
static float ratio = 0.004f;
|
||||
static int seed = 0;
|
||||
|
||||
void _zz_setseed(int seed)
|
||||
static void readchars(int *, char const *);
|
||||
|
||||
void _zz_protect(char const *list)
|
||||
{
|
||||
_zz_seed = seed;
|
||||
readchars(protect, list);
|
||||
}
|
||||
|
||||
void _zz_setratio(float ratio)
|
||||
void _zz_refuse(char const *list)
|
||||
{
|
||||
_zz_ratio = ratio;
|
||||
if(_zz_ratio < 0.0f)
|
||||
_zz_ratio = 0.0f;
|
||||
else if(_zz_ratio > 5.0f)
|
||||
_zz_ratio = 5.0f;
|
||||
readchars(refuse, list);
|
||||
}
|
||||
|
||||
void _zz_setseed(int s)
|
||||
{
|
||||
seed = s;
|
||||
}
|
||||
|
||||
void _zz_setratio(float r)
|
||||
{
|
||||
if(r < 0.0f)
|
||||
r = 0.0f;
|
||||
else if(r > 5.0f)
|
||||
r = 5.0f;
|
||||
ratio = r;
|
||||
}
|
||||
|
||||
void _zz_fuzz(int fd, uint8_t *buf, uint64_t len)
|
||||
@@ -81,10 +96,10 @@ void _zz_fuzz(int fd, uint8_t *buf, uint64_t len)
|
||||
memset(fuzz->data, 0, CHUNKBYTES);
|
||||
|
||||
/* Add some random dithering to handle ratio < 1.0/CHUNKBYTES */
|
||||
_zz_srand(_zz_seed ^ chunkseed);
|
||||
todo = (int)((_zz_ratio * (8 * CHUNKBYTES * 1000)
|
||||
+ _zz_rand(1000)) / 1000.0);
|
||||
_zz_srand(_zz_seed ^ chunkseed ^ (todo * MAGIC2));
|
||||
_zz_srand(seed ^ chunkseed);
|
||||
todo = (int)((ratio * (8 * CHUNKBYTES * 1000)
|
||||
+ _zz_rand(1000)) / 1000.0);
|
||||
_zz_srand(seed ^ chunkseed ^ (todo * MAGIC2));
|
||||
|
||||
while(todo--)
|
||||
{
|
||||
@@ -107,12 +122,12 @@ void _zz_fuzz(int fd, uint8_t *buf, uint64_t len)
|
||||
{
|
||||
uint8_t byte = aligned_buf[j];
|
||||
|
||||
if(_zz_protect[byte])
|
||||
if(protect[byte])
|
||||
continue;
|
||||
|
||||
byte ^= fuzz->data[j % CHUNKBYTES];
|
||||
|
||||
if(_zz_refuse[byte])
|
||||
if(refuse[byte])
|
||||
continue;
|
||||
|
||||
aligned_buf[j] = byte;
|
||||
@@ -120,3 +135,69 @@ void _zz_fuzz(int fd, uint8_t *buf, uint64_t len)
|
||||
}
|
||||
}
|
||||
|
||||
static void readchars(int *table, char const *list)
|
||||
{
|
||||
static char const hex[] = "0123456789abcdef0123456789ABCDEF";
|
||||
char const *tmp;
|
||||
int a, b;
|
||||
|
||||
memset(table, 0, 256 * sizeof(int));
|
||||
|
||||
for(tmp = list, a = b = -1; *tmp; tmp++)
|
||||
{
|
||||
int new;
|
||||
|
||||
if(*tmp == '\\' && tmp[1] == '\0')
|
||||
new = '\\';
|
||||
else if(*tmp == '\\')
|
||||
{
|
||||
tmp++;
|
||||
if(*tmp == 'n')
|
||||
new = '\n';
|
||||
else if(*tmp == 'r')
|
||||
new = '\r';
|
||||
else if(*tmp == 't')
|
||||
new = '\t';
|
||||
else if(tmp[0] >= '0' && tmp[0] <= '7' && tmp[1] >= '0'
|
||||
&& tmp[1] <= '7' && tmp[2] >= '0' && tmp[2] <= '7')
|
||||
{
|
||||
new = tmp[2] - '0';
|
||||
new |= (int)(tmp[1] - '0') << 3;
|
||||
new |= (int)(tmp[0] - '0') << 6;
|
||||
tmp += 2;
|
||||
}
|
||||
else if((*tmp == 'x' || *tmp == 'X')
|
||||
&& tmp[1] && strchr(hex, tmp[1])
|
||||
&& tmp[2] && strchr(hex, tmp[2]))
|
||||
{
|
||||
new = ((strchr(hex, tmp[1]) - hex) & 0xf) << 4;
|
||||
new |= (strchr(hex, tmp[2]) - hex) & 0xf;
|
||||
tmp += 2;
|
||||
}
|
||||
else
|
||||
new = (unsigned char)*tmp; /* XXX: OK for \\, but what else? */
|
||||
}
|
||||
else
|
||||
new = (unsigned char)*tmp;
|
||||
|
||||
if(a != -1 && b == '-' && a <= new)
|
||||
{
|
||||
while(a <= new)
|
||||
table[a++] = 1;
|
||||
a = b = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(a != -1)
|
||||
table[a] = 1;
|
||||
a = b;
|
||||
b = new;
|
||||
}
|
||||
}
|
||||
|
||||
if(a != -1)
|
||||
table[a] = 1;
|
||||
if(b != -1)
|
||||
table[b] = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
* fuzz.h: fuzz functions
|
||||
*/
|
||||
|
||||
extern void _zz_protect(char const *);
|
||||
extern void _zz_refuse(char const *);
|
||||
extern void _zz_setseed(int);
|
||||
extern void _zz_setratio(float);
|
||||
|
||||
extern void _zz_fuzz(int, uint8_t *, uint64_t);
|
||||
|
||||
|
||||
+2
-7
@@ -37,7 +37,6 @@
|
||||
#include "libzzuf.h"
|
||||
#include "debug.h"
|
||||
#include "load.h"
|
||||
#include "chars.h"
|
||||
#include "fd.h"
|
||||
#include "fuzz.h"
|
||||
|
||||
@@ -48,10 +47,6 @@ int _zz_hasdebug = 0;
|
||||
int _zz_signal = 0;
|
||||
int _zz_network = 0;
|
||||
|
||||
/* Global tables */
|
||||
int _zz_protect[256];
|
||||
int _zz_refuse[256];
|
||||
|
||||
/* Library initialisation shit */
|
||||
void _zz_init(void)
|
||||
{
|
||||
@@ -71,11 +66,11 @@ void _zz_init(void)
|
||||
|
||||
tmp = getenv("ZZUF_PROTECT");
|
||||
if(tmp && *tmp)
|
||||
_zz_readchars(_zz_protect, tmp);
|
||||
_zz_protect(tmp);
|
||||
|
||||
tmp = getenv("ZZUF_REFUSE");
|
||||
if(tmp && *tmp)
|
||||
_zz_readchars(_zz_refuse, tmp);
|
||||
_zz_refuse(tmp);
|
||||
|
||||
tmp = getenv("ZZUF_INCLUDE");
|
||||
if(tmp && *tmp)
|
||||
|
||||
@@ -41,10 +41,6 @@ extern int _zz_hasdebug;
|
||||
extern int _zz_signal;
|
||||
extern int _zz_network;
|
||||
|
||||
/* Internal tables TODO: merge them and use bitmasks */
|
||||
extern int _zz_protect[256];
|
||||
extern int _zz_refuse[256];
|
||||
|
||||
/* Library initialisation shit */
|
||||
extern void _zz_init(void) __attribute__((constructor));
|
||||
extern void _zz_fini(void) __attribute__((destructor));
|
||||
|
||||
+2
-7
@@ -39,7 +39,6 @@
|
||||
|
||||
#include "libzzuf.h"
|
||||
#include "random.h"
|
||||
#include "chars.h"
|
||||
#include "fd.h"
|
||||
#include "fuzz.h"
|
||||
|
||||
@@ -55,10 +54,6 @@ static void version(void);
|
||||
static void usage(void);
|
||||
#endif
|
||||
|
||||
/* Global tables */
|
||||
int _zz_protect[256];
|
||||
int _zz_refuse[256];
|
||||
|
||||
static struct child_list
|
||||
{
|
||||
enum status
|
||||
@@ -233,9 +228,9 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if(protect)
|
||||
_zz_readchars(_zz_protect, protect);
|
||||
_zz_protect(protect);
|
||||
if(refuse)
|
||||
_zz_readchars(_zz_refuse, protect);
|
||||
_zz_refuse(refuse);
|
||||
|
||||
_zz_fd_init();
|
||||
_zz_register(0);
|
||||
|
||||
Reference in New Issue
Block a user