Changeset 1660 for zzuf


Ignore:
Timestamp:
Jan 13, 2007, 11:50:38 AM (13 years ago)
Author:
Sam Hocevar
Message:
  • Implemented -D/--delay to avoid fork bombs.
Location:
zzuf/trunk
Files:
2 edited

Legend:

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

    r1658 r1660  
    55\fBzzuf\fR [\fB\-cdiMnqSx\fR] [\fB\-r\fR \fIratio\fR] [\fB\-s\fR \fIseed\fR|\fB\-s\fR \fIstart:stop\fR]
    66.br
    7                  [\fB\-F\fR \fIforks\fR] [\fB\-C\fR \fIcrashes\fR] [\fB\-B\fR \fIbytes\fR] [\fB\-T\fR \fIseconds\fR]
    8 .br
    9                  [\fB\-M\fR \fImegabytes\fR] [\fB\-P\fR \fIprotect\fR] [\fB\-R\fR \fIrefuse\fR]
     7                 [\fB\-D\fR \fIdelay\fR] [\fB\-F\fR \fIforks\fR] [\fB\-C\fR \fIcrashes\fR] [\fB\-B\fR \fIbytes\fR]
     8.br
     9                 [\fB\-T\fR \fIseconds\fR] [\fB\-M\fR \fImegabytes\fR] [\fB\-P\fR \fIprotect\fR] [\fB\-R\fR \fIrefuse\fR]
    1010.br
    1111                 [\fB\-I\fR \fIinclude\fR] [\fB\-E\fR \fIexclude\fR] [\fIPROGRAM\fR [\fB\-\-\fR] [\fIARGS\fR]...]
     
    7070Activate the display of debug messages.
    7171.TP
     72\fB\-D\fR, \fB\-\-delay\fR=\fIdelay\fR
     73Do not launch more than one process every \fIdelay\fR seconds. This option
     74should be used together with \fB\-F\fR to avoid fork bombs.
     75.TP
    7276\fB\-E\fR, \fB\-\-exclude\fR=\fIregex\fR
    7377Do not fuzz files whose name matches the \fIregex\fR regular expression. This
     
    8387
    8488This option is only relevant if the \fB\-s\fR flag is used with an interval
    85 argument.
     89argument. See also the \fB\-D\fR flag.
    8690.TP
    8791\fB\-i\fR, \fB\-\-stdin\fR
     
    242246Fuzz 2% of \fBMPlayer\fR's input bits (\fB\-r\ 0.02\fR) with seeds 0 to 9999
    243247(\fB\-s\ 0:10000\fR), disabling its standard output messages (\fB\-q\fR),
    244 launching up to three simultaneous child processes (\fB\-F\ 3\fR), killing
    245 \fBMPlayer\fR if it takes more than one minute to read the file (\fB\-T\ 60\fR)
    246 and disabling its \fBSIGSEGV\fR signal handler (\fB\-S\fR):
    247 .PP
    248 \fB    zzuf \-c \-r 0.02 \-q \-s 0:10000 \-F 3 \-T 60 \-S \\\fR
     248launching up to five simultaneous child processes (\fB\-F\ 5\fR) but wait at
     249least half a second between launches (\fB\-D\ 0.5\fR), killing \fBMPlayer\fR
     250if it takes more than one minute to read the file (\fB\-T\ 60\fR) and
     251disabling its \fBSIGSEGV\fR signal handler (\fB\-S\fR):
     252.PP
     253\fB    zzuf \-c \-r 0.02 \-q \-s 0:10000 \-F 5 \-D 0.5 \-T 60 \-S \\\fR
    249254\fB      mplayer \-\- \-benchmark \-vo null \-fps 1000 movie.avi\fR
    250255.SH RESTRICTIONS
  • zzuf/trunk/src/zzuf.c

    r1659 r1660  
    8888static int maxmem = -1;
    8989static int64_t maxtime = -1;
     90static int64_t delay = 0;
    9091static int64_t lastlaunch = 0;
    9192
     
    111112    for(;;)
    112113    {
     114#   define OPTSTR "B:cC:dD:E:F:iI:mM:nP:qr:R:s:ST:xhv"
    113115#   ifdef HAVE_GETOPT_LONG
    114116#       define MOREINFO "Try `%s --help' for more information.\n"
     
    121123            { "max-crashes", 1, NULL, 'C' },
    122124            { "debug",       0, NULL, 'd' },
     125            { "delay",       1, NULL, 'D' },
    123126            { "exclude",     1, NULL, 'E' },
    124127            { "max-forks",   1, NULL, 'F' },
     
    139142            { "version",     0, NULL, 'v' },
    140143        };
    141         int c = getopt_long(argc, argv, "B:cC:dE:F:iI:mM:nP:qr:R:s:ST:xhv",
    142                             long_options, &option_index);
     144        int c = getopt_long(argc, argv, OPTSTR, long_options, &option_index);
    143145#   else
    144146#       define MOREINFO "Try `%s -h' for more information.\n"
    145         int c = getopt(argc, argv, "B:cC:dE:F:iI:mM:nP:qr:R:s:ST:xhv");
     147        int c = getopt(argc, argv, OPTSTR);
    146148#   endif
    147149        if(c == -1)
     
    163165        case 'd': /* --debug */
    164166            setenv("ZZUF_DEBUG", "1", 1);
     167            break;
     168        case 'D': /* --delay */
     169            delay = (int64_t)(atof(optarg) * 1000000.0);
    165170            break;
    166171        case 'E': /* --exclude */
     
    422427    char buf[BUFSIZ];
    423428    int fd[3][2];
     429    int64_t now = _zz_time();
    424430    pid_t pid;
    425431    int i, j;
     
    433439    if(maxcrashes && crashes >= maxcrashes)
    434440        return; /* all jobs crashed */
     441
     442    if(delay > 0 && lastlaunch + delay > now)
     443        return; /* too early */
    435444
    436445    /* Find the empty slot */
     
    484493    }
    485494
    486     lastlaunch = _zz_time();
    487 
    488495    /* We’re the parent, acknowledge spawn */
    489     child_list[i].date = lastlaunch;
     496    child_list[i].date = now;
    490497    child_list[i].pid = pid;
    491498    for(j = 0; j < 3; j++)
     
    500507        child_list[i].ctx = _zz_md5_init();
    501508
     509    lastlaunch = now;
    502510    child_count++;
    503511    seed++;
     
    712720{
    713721    printf("Usage: zzuf [-cdimnqSx] [-r ratio] [-s seed | -s start:stop]\n");
    714     printf("                        [-F forks] [-C crashes] [-B bytes] [-T seconds]\n");
    715     printf("                        [-M bytes] [-P protect] [-R refuse]\n");
     722    printf("                        [-D delay] [-F forks] [-C crashes] [-B bytes]\n");
     723    printf("                        [-T seconds] [-M bytes] [-P protect] [-R refuse]\n");
    716724    printf("                        [-I include] [-E exclude] [PROGRAM [--] [ARGS]...]\n");
    717725#   ifdef HAVE_GETOPT_LONG
     
    730738    printf("  -C, --max-crashes <n>    stop after <n> children have crashed (default 1)\n");
    731739    printf("  -d, --debug              print debug messages\n");
     740    printf("  -D, --delay              delay between forks\n");
    732741    printf("  -E, --exclude <regex>    do not fuzz files matching <regex>\n");
    733742    printf("  -F, --max-forks <n>      number of concurrent children (default 1)\n");
     
    753762    printf("  -C <n>           stop after <n> children have crashed (default 1)\n");
    754763    printf("  -d               print debug messages\n");
     764    printf("  -D               delay between forks\n");
    755765    printf("  -E <regex>       do not fuzz files matching <regex>\n");
    756766    printf("  -F <n>           number of concurrent forks (default 1)\n");
Note: See TracChangeset for help on using the changeset viewer.