- Timestamp:
- Jul 6, 2007, 3:40:55 PM (15 years ago)
- Location:
- zzuf/trunk/src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/fd.c
r1730 r1791 35 35 #include "libzzuf.h" 36 36 #include "fd.h" 37 #include "fuzz.h" 37 38 38 39 /* Regex stuff */ … … 41 42 static int has_include = 0, has_exclude = 0; 42 43 #endif 44 45 /* File descriptor cherry picking */ 46 static int *ranges = NULL; 47 static int ranges_static[512]; 43 48 44 49 /* File descriptor stuff. When program is launched, we use the static array of … … 50 55 static struct files 51 56 { 52 int managed, locked ;57 int managed, locked, active; 53 58 int64_t pos; 54 59 /* Public stuff */ … … 88 93 (void)regex; 89 94 #endif 95 } 96 97 /* This function is the same as _zz_bytes() */ 98 void _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; 90 131 } 91 132 … … 259 300 files[i].fuzz.uflag = 0; 260 301 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 261 322 if(autoinc) 262 323 seed++; … … 312 373 } 313 374 375 int _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 314 383 int64_t _zz_getpos(int fd) 315 384 { -
zzuf/trunk/src/fd.h
r1730 r1791 33 33 extern void _zz_unlock(int); 34 34 extern int _zz_islocked(int); 35 extern int _zz_isactive(int); 35 36 extern int64_t _zz_getpos(int); 36 37 extern void _zz_setpos(int, int64_t); -
zzuf/trunk/src/fuzz.c
r1736 r1791 65 65 } 66 66 67 /* This function is the same as _zz_pick() */ 67 68 void _zz_bytes(char const *list) 68 69 { -
zzuf/trunk/src/fuzz.h
r1732 r1791 19 19 extern void _zz_fuzzing(char const *); 20 20 extern void _zz_bytes(char const *); 21 extern void _zz_pick(char const *); 21 22 extern void _zz_protect(char const *); 22 23 extern void _zz_refuse(char const *); -
zzuf/trunk/src/lib-fd.c
r1763 r1791 208 208 LOADSYM(recv); 209 209 ret = ORIG(recv)(s, buf, len, flags); 210 if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s) )210 if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s) || !_zz_isactive(s)) 211 211 return ret; 212 212 … … 241 241 LOADSYM(recvfrom); 242 242 ret = ORIG(recvfrom)(s, buf, len, flags, from, fromlen); 243 if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s) )243 if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s) || !_zz_isactive(s)) 244 244 return ret; 245 245 … … 274 274 LOADSYM(recvmsg); 275 275 ret = ORIG(recvmsg)(s, hdr, flags); 276 if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s) )276 if(!_zz_ready || !_zz_iswatched(s) || _zz_islocked(s) || !_zz_isactive(s)) 277 277 return ret; 278 278 … … 294 294 LOADSYM(read); 295 295 ret = ORIG(read)(fd, buf, count); 296 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) 296 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd) 297 || !_zz_isactive(fd)) 297 298 return ret; 298 299 … … 325 326 LOADSYM(readv); 326 327 ret = ORIG(readv)(fd, iov, count); 327 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) 328 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd) 329 || !_zz_isactive(fd)) 328 330 return ret; 329 331 … … 343 345 LOADSYM(pread); 344 346 ret = ORIG(pread)(fd, buf, count, offset); 345 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) 347 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd) 348 || !_zz_isactive(fd)) 346 349 return ret; 347 350 … … 376 379 LOADSYM(fn); \ 377 380 ret = ORIG(fn)(fd, offset, whence); \ 378 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) \ 381 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd) \ 382 || !_zz_isactive(fd)) \ 379 383 return ret; \ 380 384 debug("%s(%i, %lli, %i) = %lli", __func__, fd, \ … … 407 411 408 412 LOADSYM(aio_read); 409 if(!_zz_ready || !_zz_iswatched(fd) )413 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) 410 414 return ORIG(aio_read)(aiocbp); 411 415 … … 426 430 427 431 LOADSYM(aio_return); 428 if(!_zz_ready || !_zz_iswatched(fd) )432 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) 429 433 return ORIG(aio_return)(aiocbp); 430 434 -
zzuf/trunk/src/lib-mem.c
r1751 r1791 224 224 char *b = MAP_FAILED; \ 225 225 LOADSYM(fn); \ 226 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) \ 226 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd) \ 227 || !_zz_isactive(fd)) \ 227 228 return ORIG(fn)(start, length, prot, flags, fd, offset); \ 228 229 ret = ORIG(fn)(NULL, length, prot, flags, fd, offset); \ … … 318 319 LOADSYM(map_fd); 319 320 ret = ORIG(map_fd)(fd, offset, addr, find_space, numbytes); 320 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd)) 321 if(!_zz_ready || !_zz_iswatched(fd) || _zz_islocked(fd) 322 || !_zz_isactive(fd)) 321 323 return ret; 322 324 -
zzuf/trunk/src/lib-stream.c
r1730 r1791 176 176 LOADSYM(fn); \ 177 177 fd = fileno(stream); \ 178 if(!_zz_ready || !_zz_iswatched(fd) ) \178 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 179 179 return ORIG(fn)(stream, offset, whence); \ 180 180 _zz_lock(fd); \ … … 204 204 LOADSYM(rewind); 205 205 fd = fileno(stream); 206 if(!_zz_ready || !_zz_iswatched(fd) )206 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) 207 207 { 208 208 ORIG(rewind)(stream); … … 234 234 LOADSYM(fread); 235 235 fd = fileno(stream); 236 if(!_zz_ready || !_zz_iswatched(fd) )236 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) 237 237 return ORIG(fread)(ptr, size, nmemb, stream); 238 238 … … 295 295 LOADSYM(fn); \ 296 296 fd = fileno(stream); \ 297 if(!_zz_ready || !_zz_iswatched(fd) ) \297 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 298 298 return ORIG(fn)(stream); \ 299 299 _zz_lock(fd); \ … … 333 333 LOADSYM(fgetc); 334 334 fd = fileno(stream); 335 if(!_zz_ready || !_zz_iswatched(fd) )335 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) 336 336 return ORIG(fgets)(s, size, stream); 337 337 … … 386 386 LOADSYM(ungetc); 387 387 fd = fileno(stream); 388 if(!_zz_ready || !_zz_iswatched(fd) )388 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) 389 389 return ORIG(ungetc)(c, stream); 390 390 … … 440 440 LOADSYM(fgetc); \ 441 441 fd = fileno(stream); \ 442 if(!_zz_ready || !_zz_iswatched(fd) ) \442 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) \ 443 443 return ORIG(getdelim)(lineptr, n, delim, stream); \ 444 444 line = *lineptr; \ … … 522 522 LOADSYM(fgetc); 523 523 fd = fileno(stream); 524 if(!_zz_ready || !_zz_iswatched(fd) )524 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) 525 525 return ORIG(fgetln)(stream, len); 526 526 … … 571 571 LOADSYM(__srefill); 572 572 fd = fileno(fp); 573 if(!_zz_ready || !_zz_iswatched(fd) )573 if(!_zz_ready || !_zz_iswatched(fd) || !_zz_isactive(fd)) 574 574 return ORIG(__srefill)(fp); 575 575 -
zzuf/trunk/src/libzzuf.c
r1730 r1791 91 91 _zz_bytes(tmp); 92 92 93 tmp = getenv("ZZUF_PICK"); 94 if(tmp && *tmp) 95 _zz_pick(tmp); 96 93 97 tmp = getenv("ZZUF_PROTECT"); 94 98 if(tmp && *tmp) -
zzuf/trunk/src/opts.c
r1720 r1791 34 34 void _zz_opts_init(struct opts *opts) 35 35 { 36 opts->fuzzing = opts->bytes = opts->protect = opts->refuse = NULL; 36 opts->fuzzing = opts->bytes = opts->pick = NULL; 37 opts->protect = opts->refuse = NULL; 37 38 opts->seed = DEFAULT_SEED; 38 39 opts->endseed = DEFAULT_SEED + 1; -
zzuf/trunk/src/opts.h
r1720 r1791 21 21 char **oldargv; 22 22 char **newargv; 23 char *fuzzing, *bytes, *p rotect, *refuse;23 char *fuzzing, *bytes, *pick, *protect, *refuse; 24 24 uint32_t seed; 25 25 uint32_t endseed; -
zzuf/trunk/src/zzuf.c
r1762 r1791 158 158 #endif 159 159 #define OPTSTR OPTSTR_REGEX OPTSTR_RLIMIT \ 160 "Ab:B:C:dD:f:F:imn P:qr:R:s:ST:vxhV"160 "Ab:B:C:dD:f:F:imnp:P:qr:R:s:ST:vxhV" 161 161 #define MOREINFO "Try `%s --help' for more information.\n" 162 162 int option_index = 0; … … 185 185 { "max-memory", 1, NULL, 'M' }, 186 186 { "network", 0, NULL, 'n' }, 187 { "pick", 1, NULL, 'p' }, 187 188 { "protect", 1, NULL, 'P' }, 188 189 { "quiet", 0, NULL, 'q' }, … … 275 276 setenv("ZZUF_NETWORK", "1", 1); 276 277 break; 278 case 'p': /* --pick */ 279 opts->pick = myoptarg; 280 break; 277 281 case 'P': /* --protect */ 278 282 opts->protect = myoptarg; … … 376 380 if(opts->bytes) 377 381 setenv("ZZUF_BYTES", opts->bytes, 1); 382 if(opts->pick) 383 setenv("ZZUF_PICK", opts->pick, 1); 378 384 if(opts->protect) 379 385 setenv("ZZUF_PROTECT", opts->protect, 1); … … 428 434 if(opts->bytes) 429 435 _zz_bytes(opts->bytes); 436 if(opts->pick) 437 _zz_pick(opts->pick); 430 438 if(opts->protect) 431 439 _zz_protect(opts->protect); … … 1086 1094 #endif 1087 1095 #if defined HAVE_REGEX_H 1096 printf(" [-p descriptors] [-I include] [-E exclude]\n"); 1097 printf(" [PROGRAM [--] [ARGS]...]\n"); 1098 #else 1088 1099 printf(" [-I include] [-E exclude] [PROGRAM [--] [ARGS]...]\n"); 1089 #else1090 printf(" [PROGRAM [--] [ARGS]...]\n");1091 1100 #endif 1092 1101 printf(" zzuf -h | --help\n"); … … 1118 1127 #endif 1119 1128 printf(" -n, --network fuzz network input\n"); 1129 printf(" -p, --pick <list> only fuzz Nth descriptor with N in <list>\n"); 1120 1130 printf(" -P, --protect <list> protect bytes and characters in <list>\n"); 1121 1131 printf(" -q, --quiet do not print children's messages\n");
Note: See TracChangeset
for help on using the changeset viewer.