* Change timing functions to gettimeofday() instead of time() for more
precision.
This commit is contained in:
parent
61a673c096
commit
c5ce65e161
@ -1,3 +1,4 @@
|
|||||||
|
# $Id$
|
||||||
|
|
||||||
SUBDIRS = src test doc
|
SUBDIRS = src test doc
|
||||||
DIST_SUBDIRS = $(SUBDIRS)
|
DIST_SUBDIRS = $(SUBDIRS)
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
|
# $Id$
|
||||||
|
|
||||||
COMMON = random.c random.h fd.c fd.h fuzz.c fuzz.h
|
COMMON = random.c random.h fd.c fd.h fuzz.c fuzz.h
|
||||||
|
|
||||||
bin_PROGRAMS = zzuf
|
bin_PROGRAMS = zzuf
|
||||||
zzuf_SOURCES = zzuf.c $(COMMON) md5.c md5.h
|
zzuf_SOURCES = zzuf.c $(COMMON) md5.c md5.h timer.c timer.h
|
||||||
zzuf_CFLAGS = -DLIBDIR=\"$(libdir)/zzuf\"
|
zzuf_CFLAGS = -DLIBDIR=\"$(libdir)/zzuf\"
|
||||||
|
|
||||||
pkglib_LTLIBRARIES = libzzuf.la
|
pkglib_LTLIBRARIES = libzzuf.la
|
||||||
|
|||||||
38
src/timer.c
Normal file
38
src/timer.c
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* timer.c: timing functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#if defined HAVE_STDINT_H
|
||||||
|
# include <stdint.h>
|
||||||
|
#elif defined HAVE_INTTYPES_H
|
||||||
|
# include <inttypes.h>
|
||||||
|
#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
|
int64_t _zz_time(void)
|
||||||
|
{
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec;
|
||||||
|
}
|
||||||
|
|
||||||
20
src/timer.h
Normal file
20
src/timer.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* zzuf - general purpose fuzzer
|
||||||
|
* Copyright (c) 2006, 2007 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* timer.h: timing functions
|
||||||
|
*/
|
||||||
|
|
||||||
|
int64_t _zz_time(void);
|
||||||
|
|
||||||
21
src/zzuf.c
21
src/zzuf.c
@ -33,8 +33,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/resource.h>
|
#include <sys/resource.h>
|
||||||
@ -44,6 +42,7 @@
|
|||||||
#include "fd.h"
|
#include "fd.h"
|
||||||
#include "fuzz.h"
|
#include "fuzz.h"
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
|
#include "timer.h"
|
||||||
|
|
||||||
static void spawn_child(char **);
|
static void spawn_child(char **);
|
||||||
static void clean_children(void);
|
static void clean_children(void);
|
||||||
@ -71,7 +70,7 @@ static struct child_list
|
|||||||
pid_t pid;
|
pid_t pid;
|
||||||
int fd[3]; /* 0 is debug, 1 is stderr, 2 is stdout */
|
int fd[3]; /* 0 is debug, 1 is stderr, 2 is stdout */
|
||||||
int bytes, seed;
|
int bytes, seed;
|
||||||
time_t date;
|
int64_t date;
|
||||||
struct md5 *ctx;
|
struct md5 *ctx;
|
||||||
} *child_list;
|
} *child_list;
|
||||||
static int maxforks = 1, child_count = 0, maxcrashes = 1, crashes = 0;
|
static int maxforks = 1, child_count = 0, maxcrashes = 1, crashes = 0;
|
||||||
@ -83,7 +82,7 @@ static int maxbytes = -1;
|
|||||||
static int md5 = 0;
|
static int md5 = 0;
|
||||||
static int checkexit = 0;
|
static int checkexit = 0;
|
||||||
static int maxmem = -1;
|
static int maxmem = -1;
|
||||||
static double maxtime = -1.0;
|
static int64_t maxtime = -1;
|
||||||
|
|
||||||
#define ZZUF_FD_SET(fd, p_fdset, maxfd) \
|
#define ZZUF_FD_SET(fd, p_fdset, maxfd) \
|
||||||
if(fd >= 0) \
|
if(fd >= 0) \
|
||||||
@ -214,7 +213,7 @@ int main(int argc, char *argv[])
|
|||||||
setenv("ZZUF_SIGNAL", "1", 1);
|
setenv("ZZUF_SIGNAL", "1", 1);
|
||||||
break;
|
break;
|
||||||
case 'T': /* --max-time */
|
case 'T': /* --max-time */
|
||||||
maxtime = atof(optarg);
|
maxtime = (int64_t)(atof(optarg) * 1000000.0);
|
||||||
break;
|
break;
|
||||||
case 'x': /* --check-exit */
|
case 'x': /* --check-exit */
|
||||||
checkexit = 1;
|
checkexit = 1;
|
||||||
@ -468,7 +467,7 @@ static void spawn_child(char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We’re the parent, acknowledge spawn */
|
/* We’re the parent, acknowledge spawn */
|
||||||
child_list[i].date = time(NULL);
|
child_list[i].date = _zz_time();
|
||||||
child_list[i].pid = pid;
|
child_list[i].pid = pid;
|
||||||
for(j = 0; j < 3; j++)
|
for(j = 0; j < 3; j++)
|
||||||
{
|
{
|
||||||
@ -486,7 +485,7 @@ static void spawn_child(char **argv)
|
|||||||
|
|
||||||
static void clean_children(void)
|
static void clean_children(void)
|
||||||
{
|
{
|
||||||
time_t now = time(NULL);
|
int64_t now = _zz_time();
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
/* Terminate children if necessary */
|
/* Terminate children if necessary */
|
||||||
@ -503,8 +502,8 @@ static void clean_children(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(child_list[i].status == STATUS_RUNNING
|
if(child_list[i].status == STATUS_RUNNING
|
||||||
&& maxtime >= 0.0
|
&& maxtime >= 0
|
||||||
&& difftime(now, child_list[i].date) > maxtime)
|
&& now > child_list[i].date + maxtime)
|
||||||
{
|
{
|
||||||
fprintf(stdout, "zzuf[seed=%i]: time exceeded, sending SIGTERM\n",
|
fprintf(stdout, "zzuf[seed=%i]: time exceeded, sending SIGTERM\n",
|
||||||
child_list[i].seed);
|
child_list[i].seed);
|
||||||
@ -514,11 +513,11 @@ static void clean_children(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Kill children if necessary */
|
/* Kill children if necessary (still there after 2 seconds) */
|
||||||
for(i = 0; i < maxforks; i++)
|
for(i = 0; i < maxforks; i++)
|
||||||
{
|
{
|
||||||
if(child_list[i].status == STATUS_SIGTERM
|
if(child_list[i].status == STATUS_SIGTERM
|
||||||
&& difftime(now, child_list[i].date) > 2.0)
|
&& now > child_list[i].date + 2000000)
|
||||||
{
|
{
|
||||||
fprintf(stdout, "zzuf[seed=%i]: not responding, sending SIGKILL\n",
|
fprintf(stdout, "zzuf[seed=%i]: not responding, sending SIGKILL\n",
|
||||||
child_list[i].seed);
|
child_list[i].seed);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user