* Add --debug.

* --include and --exclude now work.
This commit is contained in:
Sam Hocevar 2006-12-15 08:42:27 +00:00 committed by sam
parent af786f13d4
commit 6e2d2746f9
4 changed files with 43 additions and 25 deletions

View File

@ -40,14 +40,8 @@ void zzuf_fuzz(int fd, uint8_t *buf, uint64_t len)
uint64_t pos;
unsigned int i;
if(!files[fd].managed)
return;
pos = files[fd].pos;
debug("fuzzing %lu bytes", (unsigned long int)len);
debug("offset is %lu", (unsigned long int)pos);
for(i = pos / CHUNK_SIZE; i < (pos + len) / CHUNK_SIZE + 1; i++)
{
uint64_t offset;

View File

@ -78,7 +78,6 @@ void zzuf_init(void)
if(tmp && *tmp)
{
_zzuf_include = malloc(sizeof(*_zzuf_include));
debug("zzuf_include = \"%s\"", tmp);
regcomp(_zzuf_include, tmp, 0);
}
@ -86,7 +85,6 @@ debug("zzuf_include = \"%s\"", tmp);
if(tmp && *tmp)
{
_zzuf_exclude = malloc(sizeof(*_zzuf_exclude));
debug("zzuf_exclude = \"%s\"", tmp);
regcomp(_zzuf_exclude, tmp, 0);
}

View File

@ -82,13 +82,20 @@ int zzuf_preload(void)
if(!_zzuf_ready) \
return ret; \
debug(STR(fn) "(\"%s\", \"%s\") = %p", path, mode, ret); \
if(ret \
&& (!_zzuf_include || !regexec(_zzuf_include, path, 0, NULL, 0)) \
&& (!_zzuf_exclude || regexec(_zzuf_exclude, path, 0, NULL, 0))) \
if(ret) \
{ \
int fd = fileno(ret); \
files[fd].managed = 1; \
files[fd].pos = 0; \
if(_zzuf_include && \
regexec(_zzuf_include, path, 0, NULL, 0) == REG_NOMATCH) \
debug("file not included, ignoring"); \
else if(_zzuf_exclude && \
regexec(_zzuf_exclude, path, 0, NULL, 0) != REG_NOMATCH) \
debug("file excluded, ignoring"); \
else \
{ \
int fd = fileno(ret); \
files[fd].managed = 1; \
files[fd].pos = 0; \
} \
} \
} while(0)
@ -105,6 +112,7 @@ FILE *fopen64(const char *path, const char *mode)
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t ret;
int fd;
if(!_zzuf_ready)
LOADSYM(fread);
@ -112,12 +120,16 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
if(!_zzuf_ready)
return ret;
fd = fileno(stream);
if(!files[fd].managed)
return ret;
debug("fread(%p, %li, %li, \"%s\") = %li",
ptr, (long int)size, (long int)nmemb, stream, (long int)ret);
if(ret > 0)
{
zzuf_fuzz(fileno(stream), ptr, ret * size);
files[fileno(stream)].pos += ret * size;
zzuf_fuzz(fd, ptr, ret * size);
files[fd].pos += ret * size;
}
return ret;
}
@ -148,12 +160,19 @@ size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
} \
\
if(ret >= 0 \
&& ((oflag & (O_RDONLY | O_RDWR | O_WRONLY)) != O_WRONLY) \
&& (!_zzuf_include || !regexec(_zzuf_include, file, 0, NULL, 0)) \
&& (!_zzuf_exclude || regexec(_zzuf_exclude, file, 0, NULL, 0))) \
&& ((oflag & (O_RDONLY | O_RDWR | O_WRONLY)) != O_WRONLY)) \
{ \
files[ret].managed = 1; \
files[ret].pos = 0; \
if(_zzuf_include && \
regexec(_zzuf_include, file, 0, NULL, 0) == REG_NOMATCH) \
debug("file not included, ignoring"); \
else if(_zzuf_exclude && \
regexec(_zzuf_exclude, file, 0, NULL, 0) != REG_NOMATCH) \
debug("file excluded, ignoring"); \
else \
{ \
files[ret].managed = 1; \
files[ret].pos = 0; \
} \
} \
} while(0)
@ -177,6 +196,9 @@ ssize_t read(int fd, void *buf, size_t count)
if(!_zzuf_ready)
return ret;
if(!files[fd].managed)
return ret;
debug("read(%i, %p, %li) = %i", fd, buf, (long int)count, ret);
if(ret > 0)
{

View File

@ -56,15 +56,16 @@ int main(int argc, char *argv[])
{ "exclude", 1, NULL, 'e' },
{ "seed", 1, NULL, 's' },
{ "percent", 1, NULL, 'p' },
{ "debug", 1, NULL, 'd' },
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
};
int c = getopt_long(argc, argv, "i:e:s:p:hv",
int c = getopt_long(argc, argv, "i:e:s:p:dhv",
long_options, &option_index);
# else
# define MOREINFO "Try `%s -h' for more information.\n"
int c = getopt(argc, argv, "i:e:s:p:hv");
int c = getopt(argc, argv, "i:e:s:p:dhv");
# endif
if(c == -1)
break;
@ -83,6 +84,9 @@ int main(int argc, char *argv[])
case 'p': /* --percent */
setenv("ZZUF_PERCENT", optarg, 1);
break;
case 'd': /* --debug */
setenv("ZZUF_DEBUG", "1", 1);
break;
case 'h': /* --help */
usage();
return 0;
@ -148,8 +152,8 @@ static void version(void)
#if defined(HAVE_GETOPT_H)
static void usage(void)
{
printf("Usage: zzuf [ -vh ] [ -i regex ] [ -e regex ]\n");
printf(" [ -p percent ] [ -s seed ] PROG ARGS...\n");
printf("Usage: zzuf [ -vdh ] [ -i regex ] [ -e regex ]\n");
printf(" [ -p percent ] [ -s seed ] PROGRAM ARGS...\n");
# ifdef HAVE_GETOPT_LONG
printf(" -h, --help display this help and exit\n");
printf(" -v, --version output version information and exit\n");