Ignore:
Timestamp:
Jul 6, 2007, 3:40:55 PM (16 years ago)
Author:
Sam Hocevar
Message:
  • Added -p flag to cherry pick file descriptors that get fuzzed.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/fd.c

    r1730 r1791  
    3535#include "libzzuf.h"
    3636#include "fd.h"
     37#include "fuzz.h"
    3738
    3839/* Regex stuff */
     
    4142static int has_include = 0, has_exclude = 0;
    4243#endif
     44
     45/* File descriptor cherry picking */
     46static int *ranges = NULL;
     47static int ranges_static[512];
    4348
    4449/* File descriptor stuff. When program is launched, we use the static array of
     
    5055static struct files
    5156{
    52     int managed, locked;
     57    int managed, locked, active;
    5358    int64_t pos;
    5459    /* Public stuff */
     
    8893    (void)regex;
    8994#endif
     95}
     96
     97/* This function is the same as _zz_bytes() */
     98void _zz_pick(char const *list)
     99{   
     100    char const *parser;
     101    unsigned int i, chunks;
     102
     103    /* Count commas */
     104    for(parser = list, chunks = 1; *parser; parser++)
     105        if(*parser == ',')
     106            chunks++;
     107
     108    /* TODO: free(ranges) if ranges != ranges_static */
     109    if(chunks >= 256)
     110        ranges = malloc((chunks + 1) * 2 * sizeof(unsigned int));
     111    else
     112        ranges = ranges_static;
     113
     114    /* Fill ranges list */
     115    for(parser = list, i = 0; i < chunks; i++)
     116    {
     117        char const *comma = strchr(parser, ',');
     118        char const *dash = strchr(parser, '-');
     119
     120        ranges[i * 2] = (dash == parser) ? 0 : atoi(parser);
     121        if(dash && (dash + 1 == comma || dash[1] == '\0'))
     122            ranges[i * 2 + 1] = ranges[i * 2]; /* special case */
     123        else if(dash && (!comma || dash < comma))
     124            ranges[i * 2 + 1] = atoi(dash + 1) + 1;
     125        else
     126            ranges[i * 2 + 1] = ranges[i * 2] + 1;
     127        parser = comma + 1;
     128    }
     129
     130    ranges[i * 2] = ranges[i * 2 + 1] = 0;
    90131}
    91132
     
    259300    files[i].fuzz.uflag = 0;
    260301
     302    /* Check whether we should ignore the fd */
     303    if(ranges)
     304    {
     305        static int idx = 0;
     306        int *r;
     307
     308        idx++;
     309
     310        for(r = ranges; r[1]; r += 2)
     311            if(idx >= r[0] && (r[0] == r[1] || idx < r[1]))
     312                goto range_ok;
     313
     314        files[i].active = 0;
     315    }
     316    else
     317    {
     318    range_ok:
     319        files[i].active = 1;
     320    }
     321
    261322    if(autoinc)
    262323        seed++;
     
    312373}
    313374
     375int _zz_isactive(int fd)
     376{
     377    if(fd < 0 || fd >= maxfd || fds[fd] == -1)
     378        return 1;
     379
     380    return files[fds[fd]].active;
     381}
     382
    314383int64_t _zz_getpos(int fd)
    315384{
Note: See TracChangeset for help on using the changeset viewer.