Changeset 4264


Ignore:
Timestamp:
Jan 13, 2010, 2:09:30 AM (7 years ago)
Author:
sam
Message:

Rename -t/--max-time to -U/--max-usertime, and add -t/--max-time to
roughly mean "maximum zzuf run time". Fixes bug #45.

Location:
zzuf/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/doc/zzuf.1.in

    r4253 r4264  
    33zzuf \- multiple purpose fuzzer
    44.SH SYNOPSIS
    5 \fBzzuf\fR [\fB\-AcdimnqSvx\fR] [\fB\-s\fR \fIseed\fR|\fB\-s\fR \fIstart:stop\fR] [\fB\-r\fR \fIratio\fR|\fB\-r\fR \fImin:max\fR]
    6 .br
    7        [\fB\-f\fR \fIfuzzing\fR] [\fB\-D\fR \fIdelay\fR] [\fB\-j\fR \fIjobs\fR] [\fB\-C\fR \fIcrashes\fR] [\fB\-B\fR \fIbytes\fR]
    8 .br
    9        [\fB\-t\fR \fIseconds\fR] [\fB\-T\fR \fIseconds\fR] [\fB\-M\fR \fImebibytes\fR] [\fB\-b\fR \fIranges\fR] [\fB\-p\fR \fIports\fR]
    10 .br
    11        [\fB\-P\fR \fIprotect\fR] [\fB\-R\fR \fIrefuse\fR] [\fB\-l\fR \fIlist\fR] [\fB\-I\fR \fIinclude\fR] [\fB\-E\fR \fIexclude\fR]
    12 .br
    13       [\fIPROGRAM\fR [\fIARGS\fR]...]
     5\fBzzuf\fR [\fB\-AcdimnqSvx\fR]
     6[\fB\-s\fR \fIseed\fR|\fB\-s\fR \fIstart:stop\fR]
     7[\fB\-r\fR \fIratio\fR|\fB\-r\fR \fImin:max\fR]
     8[\fB\-f\fR \fIfuzzing\fR] [\fB\-D\fR \fIdelay\fR] [\fB\-j\fR \fIjobs\fR]
     9[\fB\-C\fR \fIcrashes\fR] [\fB\-B\fR \fIbytes\fR] [\fB\-t\fR \fIseconds\fR]
     10[\fB\-T\fR \fIseconds\fR] [\fB\-U\fR \fIseconds\fR] [\fB\-M\fR \fImebibytes\fR]
     11[\fB\-b\fR \fIranges\fR] [\fB\-p\fR \fIports\fR] [\fB\-P\fR \fIprotect\fR]
     12[\fB\-R\fR \fIrefuse\fR] [\fB\-l\fR \fIlist\fR] [\fB\-I\fR \fIinclude\fR]
     13[\fB\-E\fR \fIexclude\fR] [\fIPROGRAM\fR [\fIARGS\fR]...]
    1414.br
    1515\fBzzuf \-h\fR | \fB\-\-help\fR
     
    6464standard input if no program is being fuzzed.
    6565
    66 This is useful to detect infinite loops. See also the \fB\-t\fR and \fB\-T\fR
     66This is useful to detect infinite loops. See also the \fB\-U\fR and \fB\-T\fR
    6767flags.
    6868.TP
     
    8585of 0 tells \fBzzuf\fR to never stop.
    8686
     87Note that \fBzzuf\fR will not kill any remaining children once \fIn\fR is
     88reached. To ensure that processes do not last forever, see the \fB\-U\fR
     89flag.
     90
    8791A process is considered to have crashed if any signal (such as, but not limited
    8892to, \fBSIGSEGV\fR) caused it to exit. If the \fB\-x\fR flag is used, this will
     
    9094
    9195This option is only relevant if the \fB\-s\fR flag is used with a range
    92 argument.
     96argument. See also the \fB\-t\fR flag.
    9397.TP
    9498\fB\-d\fR, \fB\-\-debug\fR
     
    288292.TP
    289293\fB\-t\fR, \fB\-\-max\-time\fR=\fIn\fR
    290 Automatically terminate child processes that run for more than \fIn\fR
    291 seconds. This is useful to detect infinite loops or processes stuck in other
    292 situations. See also the \fB\-B\fR and \fB\-T\fR flags.
     294Stop forking after \fIn\fR seconds. By default, \fBzzuf\fR runs until the
     295end of the seed range is reached.
     296
     297Note that \fBzzuf\fR will not kill any remaining children once \fIn\fR is
     298reached. To ensure that processes do not last forever, see the \fB\-U\fR
     299flag.
     300
     301This option is only relevant if the \fB\-s\fR flag is used with a range
     302argument. See also the \fB\-C\fR flag.
    293303.TP
    294304\fB\-T\fR, \fB\-\-max\-cputime\fR=\fIn\fR
     
    301311it will receive a \fBSIGKILL\fR signal after 5 seconds.
    302312
    303 This is more accurate than \fB\-t\fR because the behaviour should be
     313This is more accurate than \fB\-U\fR because the behaviour should be
    304314independent from the system load, but it does not detect processes stuck into
    305315infinite \fBselect\fR() calls because they use very little CPU time. See also
    306 the \fB\-B\fR and \fB\-t\fR flags.
     316the \fB\-B\fR and \fB\-U\fR flags.
     317.TP
     318\fB\-U\fR, \fB\-\-max\-usertime\fR=\fIn\fR
     319Automatically terminate child processes that run for more than \fIn\fR
     320seconds. This is useful to detect infinite loops or processes stuck in other
     321situations. See also the \fB\-B\fR and \fB\-T\fR flags.
    307322.TP
    308323\fB\-v\fR, \fB\-\-verbose\fR
  • zzuf/trunk/src/opts.c

    r4253 r4264  
    2828
    2929#include "common.h"
     30#include "timer.h"
    3031#include "opts.h"
    3132
     
    4445    opts->verbose = 0;
    4546    opts->maxmem = DEFAULT_MEM;
    46     opts->maxtime = -1;
     47    opts->starttime = _zz_time();
     48    opts->maxtime = 0;
     49    opts->maxusertime = -1;
    4750    opts->maxcpu = -1;
    4851    opts->delay = 0;
  • zzuf/trunk/src/opts.h

    r4253 r4264  
    3131    int verbose;
    3232    int maxmem;
     33    int64_t starttime;
    3334    int64_t maxtime;
     35    int64_t maxusertime;
    3436    int64_t delay;
    3537    int64_t lastlaunch;
  • zzuf/trunk/src/zzuf.c

    r4253 r4264  
    159159#endif
    160160#define OPTSTR "+" OPTSTR_REGEX OPTSTR_RLIMIT_MEM OPTSTR_RLIMIT_CPU \
    161                 "a:Ab:B:C:dD:e:f:F:ij:l:mnp:P:qr:R:s:St:vxhV"
     161                "a:Ab:B:C:dD:e:f:F:ij:l:mnp:P:qr:R:s:St:U:vxhV"
    162162#define MOREINFO "Try `%s --help' for more information.\n"
    163163        int option_index = 0;
     
    165165        {
    166166            /* Long option, needs arg, flag, short option */
    167             { "allow",      1, NULL, 'a' },
    168             { "autoinc",     0, NULL, 'A' },
    169             { "bytes",       1, NULL, 'b' },
    170             { "max-bytes",   1, NULL, 'B' },
    171 #if defined HAVE_REGEX_H
    172             { "cmdline",     0, NULL, 'c' },
    173 #endif
    174             { "max-crashes", 1, NULL, 'C' },
    175             { "debug",       0, NULL, 'd' },
    176             { "delay",       1, NULL, 'D' },
    177 #if defined HAVE_REGEX_H
    178             { "exclude",     1, NULL, 'E' },
    179 #endif
    180             { "fuzzing",     1, NULL, 'f' },
    181             { "stdin",       0, NULL, 'i' },
    182 #if defined HAVE_REGEX_H
    183             { "include",     1, NULL, 'I' },
    184 #endif
    185             { "jobs",        1, NULL, 'j' },
    186             { "list",        1, NULL, 'l' },
    187             { "md5",         0, NULL, 'm' },
    188             { "max-memory",  1, NULL, 'M' },
    189             { "network",     0, NULL, 'n' },
    190             { "ports",       1, NULL, 'p' },
    191             { "protect",     1, NULL, 'P' },
    192             { "quiet",       0, NULL, 'q' },
    193             { "ratio",       1, NULL, 'r' },
    194             { "refuse",      1, NULL, 'R' },
    195             { "seed",        1, NULL, 's' },
    196             { "signal",      0, NULL, 'S' },
    197             { "max-time",    1, NULL, 't' },
    198             { "max-cputime", 1, NULL, 'T' },
    199             { "verbose",     0, NULL, 'v' },
    200             { "check-exit",  0, NULL, 'x' },
    201             { "help",        0, NULL, 'h' },
    202             { "version",     0, NULL, 'V' },
    203             { NULL,          0, NULL,  0  }
     167            { "allow",        1, NULL, 'a' },
     168            { "autoinc",      0, NULL, 'A' },
     169            { "bytes",        1, NULL, 'b' },
     170            { "max-bytes",    1, NULL, 'B' },
     171#if defined HAVE_REGEX_H
     172            { "cmdline",      0, NULL, 'c' },
     173#endif
     174            { "max-crashes",  1, NULL, 'C' },
     175            { "debug",        0, NULL, 'd' },
     176            { "delay",        1, NULL, 'D' },
     177#if defined HAVE_REGEX_H
     178            { "exclude",      1, NULL, 'E' },
     179#endif
     180            { "fuzzing",      1, NULL, 'f' },
     181            { "stdin",        0, NULL, 'i' },
     182#if defined HAVE_REGEX_H
     183            { "include",      1, NULL, 'I' },
     184#endif
     185            { "jobs",         1, NULL, 'j' },
     186            { "list",         1, NULL, 'l' },
     187            { "md5",          0, NULL, 'm' },
     188            { "max-memory",   1, NULL, 'M' },
     189            { "network",      0, NULL, 'n' },
     190            { "ports",        1, NULL, 'p' },
     191            { "protect",      1, NULL, 'P' },
     192            { "quiet",        0, NULL, 'q' },
     193            { "ratio",        1, NULL, 'r' },
     194            { "refuse",       1, NULL, 'R' },
     195            { "seed",         1, NULL, 's' },
     196            { "signal",       0, NULL, 'S' },
     197            { "max-time",     1, NULL, 't' },
     198            { "max-cputime",  1, NULL, 'T' },
     199            { "max-usertime", 1, NULL, 'U' },
     200            { "verbose",      0, NULL, 'v' },
     201            { "check-exit",   0, NULL, 'x' },
     202            { "help",         0, NULL, 'h' },
     203            { "version",      0, NULL, 'V' },
     204            { NULL,           0, NULL,  0  }
    204205        };
    205206        int c = mygetopt(argc, argv, OPTSTR, long_options, &option_index);
     
    334335            if(myoptarg[0] == '=')
    335336                myoptarg++;
    336             opts->maxtime = (int64_t)(atof(myoptarg) * 1000000.0);
     337            opts->maxtime = (int64_t)atoll(myoptarg) * 1000000;
    337338            break;
    338339#if defined HAVE_SETRLIMIT && defined ZZUF_RLIMIT_CPU
     
    343344            break;
    344345#endif
     346        case 'U': /* --max-usertime */
     347            if(myoptarg[0] == '=')
     348                myoptarg++;
     349            opts->maxusertime = (int64_t)(atof(myoptarg) * 1000000.0);
     350            break;
    345351        case 'x': /* --check-exit */
    346352            opts->checkexit = 1;
     
    480486            && opts->nchild == 0)
    481487            break;
     488
     489        if(opts->maxtime && _zz_time() - opts->starttime >= opts->maxtime
     490            && opts->nchild == 0)
     491            break;
    482492    }
    483493
     
    633643        return; /* all jobs crashed */
    634644
     645    if(opts->maxtime && now - opts->starttime >= opts->maxtime)
     646        return; /* run time exceeded */
     647
    635648    if(opts->delay > 0 && opts->lastlaunch + opts->delay > now)
    636649        return; /* too early */
     
    696709
    697710        if(opts->child[i].status == STATUS_RUNNING
    698             && opts->maxtime >= 0
    699             && now > opts->child[i].date + opts->maxtime)
     711            && opts->maxusertime >= 0
     712            && now > opts->child[i].date + opts->maxusertime)
    700713        {
    701714            if(opts->verbose)
     
    981994    printf("         ... <start:stop>   specify a seed range\n");
    982995    printf("  -S, --signal              prevent children from diverting crashing signals\n");
    983     printf("  -t, --max-time <n>        kill children that run for more than <n> seconds\n");
     996    printf("  -t, --max-time <n>        stop spawning children after <n> seconds\n");
    984997    printf("  -T, --max-cputime <n>     kill children that use more than <n> CPU seconds\n");
     998    printf("  -U, --max-usertime <n>    kill children that run for more than <n> seconds\n");
    985999    printf("  -v, --verbose             print information during the run\n");
    9861000    printf("  -x, --check-exit          report processes that exit with a non-zero status\n");
Note: See TracChangeset for help on using the changeset viewer.