Changeset 1792 for zzuf/trunk


Ignore:
Timestamp:
Jul 6, 2007, 4:39:39 PM (13 years ago)
Author:
Sam Hocevar
Message:
  • Factored common range-parsing code.
Location:
zzuf/trunk/src
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • zzuf/trunk/src/Makefile.am

    r1789 r1792  
    11# $Id$
    22
    3 COMMON = random.c random.h fd.c fd.h fuzz.c fuzz.h
     3COMMON = random.c random.h ranges.c ranges.h fd.c fd.h fuzz.c fuzz.h
    44if NEED_GETOPT_LONG
    55GETOPT = mygetopt.c mygetopt.h
  • zzuf/trunk/src/fd.c

    r1791 r1792  
    11/*
    22 *  zzuf - general purpose fuzzer
    3  *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
     3 *  Copyright (c) 2006-2007 Sam Hocevar <sam@zoy.org>
    44 *                All Rights Reserved
    55 *
     
    3636#include "fd.h"
    3737#include "fuzz.h"
     38#include "ranges.h"
    3839
    3940/* Regex stuff */
     
    9899void _zz_pick(char const *list)
    99100{   
    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 
    108101    /* 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;
     102    ranges = _zz_allocrange(list, ranges_static);
    131103}
    132104
     
    304276    {
    305277        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;
     278
     279        files[i].active = _zz_isinrange(++idx, ranges);
    315280    }
    316281    else
    317     {
    318     range_ok:
    319282        files[i].active = 1;
    320     }
    321283
    322284    if(autoinc)
  • zzuf/trunk/src/fuzz.c

    r1791 r1792  
    11/*
    22 *  zzuf - general purpose fuzzer
    3  *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
     3 *  Copyright (c) 2006-2007 Sam Hocevar <sam@zoy.org>
    44 *                All Rights Reserved
    55 *
     
    3333#include "fuzz.h"
    3434#include "fd.h"
     35#include "ranges.h"
    3536
    3637#define MAGIC1 0x33ea84f7
     
    6869void _zz_bytes(char const *list)
    6970{
    70     char const *parser;
    71     unsigned int i, chunks;
    72 
    73     /* Count commas */
    74     for(parser = list, chunks = 1; *parser; parser++)
    75         if(*parser == ',')
    76             chunks++;
    77 
    7871    /* TODO: free(ranges) if ranges != ranges_static */
    79     if(chunks >= 256)
    80         ranges = malloc((chunks + 1) * 2 * sizeof(unsigned int));
    81     else
    82         ranges = ranges_static;
    83 
    84     /* Fill ranges list */
    85     for(parser = list, i = 0; i < chunks; i++)
    86     {
    87         char const *comma = strchr(parser, ',');
    88         char const *dash = strchr(parser, '-');
    89 
    90         ranges[i * 2] = (dash == parser) ? 0 : atoi(parser);
    91         if(dash && (dash + 1 == comma || dash[1] == '\0'))
    92             ranges[i * 2 + 1] = ranges[i * 2]; /* special case */
    93         else if(dash && (!comma || dash < comma))
    94             ranges[i * 2 + 1] = atoi(dash + 1) + 1;
    95         else
    96             ranges[i * 2 + 1] = ranges[i * 2] + 1;
    97         parser = comma + 1;
    98     }
    99 
    100     ranges[i * 2] = ranges[i * 2 + 1] = 0;
     72    ranges = _zz_allocrange(list, ranges_static);
    10173}
    10274
     
    162134        for(j = start; j < stop; j++)
    163135        {
    164             int *r;
    165136            uint8_t byte, fuzzbyte;
    166137
    167             if(!ranges)
    168                 goto range_ok;
    169 
    170             for(r = ranges; r[1]; r += 2)
    171                 if(j >= r[0] && (r[0] == r[1] || j < r[1]))
    172                     goto range_ok;
    173 
    174             continue; /* Not in one of the ranges, skip byte */
    175 
    176         range_ok:
     138            if(ranges && !_zz_isinrange(j, ranges))
     139                continue; /* Not in one of the ranges, skip byte */
     140
    177141            byte = aligned_buf[j];
    178142
Note: See TracChangeset for help on using the changeset viewer.