Changeset 1623 for zzuf/trunk/src/zzuf.c
- Timestamp:
- Jan 8, 2007, 6:50:34 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/zzuf.c
r1616 r1623 42 42 #include "fd.h" 43 43 #include "fuzz.h" 44 #include "md5.h" 44 45 45 46 static void spawn_child(char **); … … 70 71 int bytes, seed; 71 72 time_t date; 73 struct md5 *ctx; 72 74 } *child_list; 73 75 static int maxforks = 1, child_count = 0, maxcrashes = 1, crashes = 0; … … 77 79 static int quiet = 0; 78 80 static int maxbytes = -1; 81 static int md5 = 0; 79 82 static double maxtime = -1.0; 80 83 … … 115 118 { "stdin", 0, NULL, 'i' }, 116 119 { "include", 1, NULL, 'I' }, 120 { "md5", 0, NULL, 'M' }, 117 121 { "network", 0, NULL, 'n' }, 118 122 { "protect", 1, NULL, 'P' }, … … 126 130 { "version", 0, NULL, 'v' }, 127 131 }; 128 int c = getopt_long(argc, argv, "B:cC:dE:F:iI: nP:qr:R:s:ST:hv",132 int c = getopt_long(argc, argv, "B:cC:dE:F:iI:MnP:qr:R:s:ST:hv", 129 133 long_options, &option_index); 130 134 # else 131 135 # define MOREINFO "Try `%s -h' for more information.\n" 132 int c = getopt(argc, argv, "B:cC:dE:F:iI: nP:qr:R:s:ST:hv");136 int c = getopt(argc, argv, "B:cC:dE:F:iI:MnP:qr:R:s:ST:hv"); 133 137 # endif 134 138 if(c == -1) … … 172 176 return EXIT_FAILURE; 173 177 } 178 break; 179 case 'M': /* --md5 */ 180 md5 = 1; 174 181 break; 175 182 case 'n': /* --network */ … … 220 227 if(optind >= argc) 221 228 { 229 uint8_t md5sum[16]; 230 struct md5 *ctx = NULL; 231 232 if(md5) 233 ctx = _zz_md5_init(); 234 222 235 if(endseed != seed + 1) 223 236 { … … 246 259 _zz_addpos(0, ret); 247 260 248 fwrite(buf, 1, ret, stdout); 261 if(md5) 262 _zz_md5_add(ctx, buf, ret); 263 else 264 fwrite(buf, 1, ret, stdout); 265 } 266 267 if(md5) 268 { 269 _zz_md5_fini(md5sum, ctx); 270 fprintf(stdout, "zzuf[seed=%i]: %.02x%.02x%.02x%.02x%.02x%.02x" 271 "%.02x%.02x%.02x%.02x%.02x%.02x%.02x%.02x%.02x%.02x\n", 272 seed, md5sum[0], md5sum[1], md5sum[2], md5sum[3], 273 md5sum[4], md5sum[5], md5sum[6], md5sum[7], 274 md5sum[8], md5sum[9], md5sum[10], md5sum[11], 275 md5sum[12], md5sum[13], md5sum[14], md5sum[15]); 276 fflush(stdout); 249 277 } 250 278 … … 370 398 int i, j; 371 399 372 /* Find anempty slot */400 /* Find the empty slot */ 373 401 for(i = 0; i < maxforks; i++) 374 402 if(child_list[i].status == STATUS_FREE) … … 409 437 exit(EXIT_FAILURE); 410 438 } 411 break; 412 default: 413 /* We’re the parent, acknowledge spawn */ 414 child_list[i].date = time(NULL); 415 child_list[i].pid = pid; 416 for(j = 0; j < 3; j++) 417 { 418 close(fd[j][1]); 419 child_list[i].fd[j] = fd[j][0]; 420 } 421 child_list[i].bytes = 0; 422 child_list[i].seed = seed; 423 child_list[i].status = STATUS_RUNNING; 424 child_count++; 425 seed++; 426 break; 427 } 439 return; 440 } 441 442 /* We’re the parent, acknowledge spawn */ 443 child_list[i].date = time(NULL); 444 child_list[i].pid = pid; 445 for(j = 0; j < 3; j++) 446 { 447 close(fd[j][1]); 448 child_list[i].fd[j] = fd[j][0]; 449 } 450 child_list[i].bytes = 0; 451 child_list[i].seed = seed; 452 child_list[i].status = STATUS_RUNNING; 453 if(md5) 454 child_list[i].ctx = _zz_md5_init(); 455 child_count++; 456 seed++; 428 457 } 429 458 … … 474 503 for(i = 0; i < maxforks; i++) 475 504 { 505 uint8_t md5sum[16]; 476 506 int status; 477 507 pid_t pid; … … 503 533 close(child_list[i].fd[j]); 504 534 535 if(md5) 536 { 537 _zz_md5_fini(md5sum, child_list[i].ctx); 538 fprintf(stdout, "zzuf[seed=%i]: %.02x%.02x%.02x%.02x%.02x%.02x" 539 "%.02x%.02x%.02x%.02x%.02x%.02x%.02x%.02x%.02x%.02x\n", 540 child_list[i].seed, md5sum[0], md5sum[1], md5sum[2], 541 md5sum[3], md5sum[4], md5sum[5], md5sum[6], md5sum[7], 542 md5sum[8], md5sum[9], md5sum[10], md5sum[11], md5sum[12], 543 md5sum[13], md5sum[14], md5sum[15]); 544 } 505 545 child_list[i].status = STATUS_FREE; 506 546 child_count--; … … 538 578 for(i = 0, j = 0; i < maxforks; i += (j == 2), j = (j + 1) % 3) 539 579 { 540 charbuf[BUFSIZ];580 uint8_t buf[BUFSIZ]; 541 581 542 582 if(child_list[i].status != STATUS_RUNNING) … … 552 592 if(j != 0) 553 593 child_list[i].bytes += ret; 554 if(!quiet || j == 0) 594 595 if(md5 && j > 0) 596 _zz_md5_add(child_list[i].ctx, buf, ret); 597 else if(!quiet || j == 0) 555 598 write((j < 2) ? STDERR_FILENO : STDOUT_FILENO, buf, ret); 556 599 } … … 607 650 static void usage(void) 608 651 { 609 printf("Usage: zzuf [-cdi nqS] [-r ratio] [-s seed | -s start:stop]\n");610 printf(" [-F forks] [-C crashes] [-B bytes] [-T seconds]\n");611 printf(" [-P protect] [-R refuse]\n");612 printf(" [-I include] [-E exclude] [PROGRAM [ARGS]...]\n");652 printf("Usage: zzuf [-cdiMnqS] [-r ratio] [-s seed | -s start:stop]\n"); 653 printf(" [-F forks] [-C crashes] [-B bytes] [-T seconds]\n"); 654 printf(" [-P protect] [-R refuse]\n"); 655 printf(" [-I include] [-E exclude] [PROGRAM [ARGS]...]\n"); 613 656 # ifdef HAVE_GETOPT_LONG 614 657 printf(" zzuf -h | --help\n"); … … 630 673 printf(" -i, --stdin fuzz standard input\n"); 631 674 printf(" -I, --include <regex> only fuzz files matching <regex>\n"); 675 printf(" -M, --md5 compute the output's MD5 hash\n"); 632 676 printf(" -n, --network fuzz network input\n"); 633 677 printf(" -P, --protect <list> protect bytes and characters in <list>\n"); … … 650 694 printf(" -i fuzz standard input\n"); 651 695 printf(" -I <regex> only fuzz files matching <regex>\n"); 696 printf(" -M compute the output's MD5 hash\n"); 652 697 printf(" -n fuzz network input\n"); 653 698 printf(" -P <list> protect bytes and characters in <list>\n");
Note: See TracChangeset
for help on using the changeset viewer.