Changeset 1733 for zzuf/trunk/src/zzuf.c
- Timestamp:
- Feb 1, 2007, 11:33:07 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/zzuf.c
r1729 r1733 24 24 # include <inttypes.h> 25 25 #endif 26 #if defined HAVE_GETOPT_H 26 #if !defined HAVE_GETOPT_LONG 27 # include "mygetopt.h" 28 #elif defined HAVE_GETOPT_H 27 29 # include <getopt.h> 28 30 #endif … … 63 65 #include "timer.h" 64 66 67 #if defined HAVE_GETOPT_LONG 68 # define mygetopt getopt_long 69 # define myoptind optind 70 # define myoptarg optarg 71 # define myoption option 72 #endif 73 65 74 #if !defined SIGKILL 66 75 # define SIGKILL 9 … … 94 103 #endif 95 104 static void version(void); 96 #if defined HAVE_GETOPT_H97 105 static void usage(void); 98 #endif99 106 100 107 #if defined HAVE_WINDOWS_H … … 125 132 #endif 126 133 int i; 127 #if !defined HAVE_GETOPT_H128 # define MOREINFO "Usage: %s message...\n"129 int optind = 1;130 #endif131 134 132 135 _zz_opts_init(opts); 133 136 134 #if defined HAVE_GETOPT_H135 137 for(;;) 136 138 { 137 # if defined HAVE_REGEX_H 138 # define OPTSTR "Ab:B:cC:dD:E:f:F:iI:mM:nP:qr:R:s:ST:vxhV" 139 # else 140 # define OPTSTR "Ab:B:C:dD:f:F:imM:nP:qr:R:s:ST:vxhV" 141 # endif 142 # if defined HAVE_GETOPT_LONG 143 # define MOREINFO "Try `%s --help' for more information.\n" 139 #if defined HAVE_REGEX_H 140 # define OPTSTR "Ab:B:cC:dD:E:f:F:iI:mM:nP:qr:R:s:ST:vxhV" 141 #else 142 # define OPTSTR "Ab:B:C:dD:f:F:imM:nP:qr:R:s:ST:vxhV" 143 #endif 144 #define MOREINFO "Try `%s --help' for more information.\n" 144 145 int option_index = 0; 145 static struct option long_options[] =146 static struct myoption long_options[] = 146 147 { 147 148 /* Long option, needs arg, flag, short option */ … … 180 181 { NULL, 0, NULL, 0 } 181 182 }; 182 int c = getopt_long(argc, argv, OPTSTR, long_options, &option_index); 183 # else 184 # define MOREINFO "Try `%s -h' for more information.\n" 185 int c = getopt(argc, argv, OPTSTR); 186 # endif 183 int c = mygetopt(argc, argv, OPTSTR, long_options, &option_index); 184 187 185 if(c == -1) 188 186 break; … … 194 192 break; 195 193 case 'b': /* --bytes */ 196 opts->bytes = optarg;194 opts->bytes = myoptarg; 197 195 break; 198 196 case 'B': /* --max-bytes */ 199 opts->maxbytes = atoi( optarg);197 opts->maxbytes = atoi(myoptarg); 200 198 break; 201 199 #if defined HAVE_REGEX_H … … 205 203 #endif 206 204 case 'C': /* --max-crashes */ 207 opts->maxcrashes = atoi( optarg);205 opts->maxcrashes = atoi(myoptarg); 208 206 if(opts->maxcrashes <= 0) 209 207 opts->maxcrashes = 0; … … 213 211 break; 214 212 case 'D': /* --delay */ 215 opts->delay = (int64_t)(atof( optarg) * 1000000.0);213 opts->delay = (int64_t)(atof(myoptarg) * 1000000.0); 216 214 break; 217 215 #if defined HAVE_REGEX_H 218 216 case 'E': /* --exclude */ 219 exclude = merge_regex(exclude, optarg);217 exclude = merge_regex(exclude, myoptarg); 220 218 if(!exclude) 221 219 { 222 printf("%s: invalid regex -- `%s'\n", argv[0], optarg); 220 fprintf(stderr, "%s: invalid regex -- `%s'\n", 221 argv[0], myoptarg); 223 222 _zz_opts_fini(opts); 224 223 return EXIT_FAILURE; … … 227 226 #endif 228 227 case 'f': /* --fuzzing */ 229 opts->fuzzing = optarg;228 opts->fuzzing = myoptarg; 230 229 break; 231 230 case 'F': /* --max-forks */ 232 opts->maxchild = atoi( optarg) > 1 ? atoi(optarg) : 1;231 opts->maxchild = atoi(myoptarg) > 1 ? atoi(myoptarg) : 1; 233 232 break; 234 233 case 'i': /* --stdin */ … … 237 236 #if defined HAVE_REGEX_H 238 237 case 'I': /* --include */ 239 include = merge_regex(include, optarg);238 include = merge_regex(include, myoptarg); 240 239 if(!include) 241 240 { 242 printf("%s: invalid regex -- `%s'\n", argv[0], optarg); 241 fprintf(stderr, "%s: invalid regex -- `%s'\n", 242 argv[0], myoptarg); 243 243 _zz_opts_fini(opts); 244 244 return EXIT_FAILURE; … … 252 252 case 'M': /* --max-memory */ 253 253 setenv("ZZUF_MEMORY", "1", 1); 254 opts->maxmem = atoi( optarg);254 opts->maxmem = atoi(myoptarg); 255 255 break; 256 256 #endif … … 259 259 break; 260 260 case 'P': /* --protect */ 261 opts->protect = optarg;261 opts->protect = myoptarg; 262 262 break; 263 263 case 'q': /* --quiet */ … … 265 265 break; 266 266 case 'r': /* --ratio */ 267 tmp = strchr( optarg, ':');268 opts->minratio = atof( optarg);267 tmp = strchr(myoptarg, ':'); 268 opts->minratio = atof(myoptarg); 269 269 opts->maxratio = tmp ? atof(tmp + 1) : opts->minratio; 270 270 break; 271 271 case 'R': /* --refuse */ 272 opts->refuse = optarg;272 opts->refuse = myoptarg; 273 273 break; 274 274 case 's': /* --seed */ 275 tmp = strchr( optarg, ':');276 opts->seed = atol( optarg);275 tmp = strchr(myoptarg, ':'); 276 opts->seed = atol(myoptarg); 277 277 opts->endseed = tmp ? (uint32_t)atoi(tmp + 1) : opts->seed + 1; 278 278 break; … … 281 281 break; 282 282 case 'T': /* --max-time */ 283 opts->maxtime = (int64_t)(atof( optarg) * 1000000.0);283 opts->maxtime = (int64_t)(atof(myoptarg) * 1000000.0); 284 284 break; 285 285 case 'x': /* --check-exit */ … … 298 298 return 0; 299 299 default: 300 printf("%s: invalid option -- %c\n", argv[0], c);300 fprintf(stderr, "%s: invalid option -- %c\n", argv[0], c); 301 301 printf(MOREINFO, argv[0]); 302 302 _zz_opts_fini(opts); … … 304 304 } 305 305 } 306 #endif307 306 308 307 _zz_setratio(opts->minratio, opts->maxratio); … … 310 309 311 310 /* If asked to read from the standard input */ 312 if( optind >= argc)311 if(myoptind >= argc) 313 312 { 314 313 if(opts->endseed != opts->seed + 1) 315 314 { 316 printf("%s: seed ranges are incompatible with stdin fuzzing\n",317 argv[0]);315 fprintf(stderr, "%s: seed ranges are incompatible with " 316 "stdin fuzzing\n", argv[0]); 318 317 printf(MOREINFO, argv[0]); 319 318 _zz_opts_fini(opts); … … 333 332 int dashdash = 0; 334 333 335 for(i = optind + 1; i < argc; i++)334 for(i = myoptind + 1; i < argc; i++) 336 335 { 337 336 if(dashdash) … … 367 366 /* Create new argv */ 368 367 opts->oldargv = argv; 369 opts->newargv = malloc((argc - optind + 1) * sizeof(char *));370 memcpy(opts->newargv, argv + optind, (argc -optind) * sizeof(char *));371 opts->newargv[argc - optind] = (char *)NULL;368 opts->newargv = malloc((argc - myoptind + 1) * sizeof(char *)); 369 memcpy(opts->newargv, argv + myoptind, (argc - myoptind) * sizeof(char *)); 370 opts->newargv[argc - myoptind] = (char *)NULL; 372 371 373 372 /* Main loop */ … … 1051 1050 } 1052 1051 1053 #if defined HAVE_GETOPT_H1054 1052 static void usage(void) 1055 1053 { … … 1066 1064 printf(" [PROGRAM [--] [ARGS]...]\n"); 1067 1065 #endif 1068 # if defined HAVE_GETOPT_LONG1069 1066 printf(" zzuf -h | --help\n"); 1070 1067 printf(" zzuf -V | --version\n"); 1071 # else1072 printf(" zzuf -h\n");1073 printf(" zzuf -V\n");1074 # endif1075 1068 printf("Run PROGRAM with optional arguments ARGS and fuzz its input.\n"); 1076 1069 printf("\n"); 1077 1070 printf("Mandatory arguments to long options are mandatory for short options too.\n"); 1078 # if defined HAVE_GETOPT_LONG1079 1071 printf(" -A, --autoinc increment seed each time a new file is opened\n"); 1080 1072 printf(" -b, --bytes <ranges> only fuzz bytes at offsets within <ranges>\n"); … … 1113 1105 printf(" -h, --help display this help and exit\n"); 1114 1106 printf(" -V, --version output version information and exit\n"); 1115 # else1116 printf(" -A increment seed each time a new file is opened\n");1117 printf(" -b <ranges> only fuzz bytes at offsets within <ranges>\n");1118 printf(" -B <n> kill children that output more than <n> bytes\n");1119 #if defined HAVE_REGEX_H1120 printf(" -c only fuzz files specified in the command line\n");1121 #endif1122 printf(" -C <n> stop after <n> children have crashed (default 1)\n");1123 printf(" -d print debug messages\n");1124 printf(" -D delay between forks\n");1125 #if defined HAVE_REGEX_H1126 printf(" -E <regex> do not fuzz files matching <regex>\n");1127 #endif1128 printf(" -f <mode> use fuzzing mode <mode>\n");1129 printf(" -F <n> number of concurrent forks (default 1)\n");1130 printf(" -i fuzz standard input\n");1131 #if defined HAVE_REGEX_H1132 printf(" -I <regex> only fuzz files matching <regex>\n");1133 #endif1134 printf(" -m compute the output's MD5 hash\n");1135 #if defined HAVE_SETRLIMIT1136 printf(" -M maximum child virtual memory size in MB\n");1137 #endif1138 printf(" -n fuzz network input\n");1139 printf(" -P <list> protect bytes and characters in <list>\n");1140 printf(" -q do not print the fuzzed application's messages\n");1141 printf(" -r <ratio> bit fuzzing ratio (default %g)\n", DEFAULT_RATIO);1142 printf(" <start:stop> specify a ratio range\n");1143 printf(" -R <list> refuse bytes and characters in <list>\n");1144 printf(" -s <seed> random seed (default %i)\n", DEFAULT_SEED);1145 printf(" <start:stop> specify a seed range\n");1146 printf(" -S prevent children from diverting crashing signals\n");1147 printf(" -T <n> kill children that run for more than <n> seconds\n");1148 printf(" -v print information during the run\n");1149 printf(" -x report processes that exit with a non-zero status\n");1150 printf(" -h display this help and exit\n");1151 printf(" -V output version information and exit\n");1152 # endif1153 1107 printf("\n"); 1154 1108 printf("Written by Sam Hocevar. Report bugs to <sam@zoy.org>.\n"); 1155 1109 } 1156 #endif 1157 1110
Note: See TracChangeset
for help on using the changeset viewer.