- Timestamp:
- Jan 7, 2007, 7:18:50 PM (14 years ago)
- Location:
- zzuf/trunk/src
- Files:
-
- 2 added
- 9 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
zzuf/trunk/src/Makefile.am
r1590 r1613 1 1 2 2 bin_PROGRAMS = zzuf 3 zzuf_SOURCES = zzuf.c 4 AM_CPPFLAGS = -DLIBDIR=\"$(libdir)/zzuf\"3 zzuf_SOURCES = zzuf.c random.c random.h chars.c chars.h fd.c fd.h fuzz.c fuzz.h 4 zzuf_CFLAGS = -DLIBDIR=\"$(libdir)/zzuf\" 5 5 6 6 pkglib_LTLIBRARIES = libzzuf.la 7 7 libzzuf_la_SOURCES = libzzuf.c libzzuf.h fuzz.c fuzz.h debug.c debug.h \ 8 8 load-fd.c load-signal.c load-stream.c load.h \ 9 random.c random.h9 fd.c fd.h chars.c chars.h random.c random.h 10 10 libzzuf_la_LDFLAGS = -avoid-version -no-undefined 11 11 libzzuf_la_LIBADD = @GETOPT_LIBS@ @DL_LIBS@ -
zzuf/trunk/src/chars.c
r1591 r1613 14 14 15 15 /* 16 * libzzuf.c: preloaded wrapper library16 * chars.c: protected/refused characters 17 17 */ 18 18 19 19 #include "config.h" 20 #define _GNU_SOURCE21 20 22 21 #if defined HAVE_STDINT_H … … 25 24 # include <inttypes.h> 26 25 #endif 27 #include <stdio.h>28 #include <unistd.h>29 #include <stdlib.h>30 26 #include <string.h> 31 #include <fcntl.h>32 #include <regex.h>33 34 #include <stdarg.h>35 #include <dlfcn.h>36 27 37 28 #include "libzzuf.h" 38 #include "debug.h" 39 #include "load.h" 29 #include "chars.h" 40 30 41 /* Global variables */ 42 int _zz_ready = 0; 43 int _zz_disabled = 0; 44 int _zz_hasdebug = 0; 45 float _zz_ratio = 0.004f; 46 int _zz_seed = 0; 47 int _zz_signal = 0; 48 int _zz_network = 0; 49 50 /* Global tables */ 51 int _zz_protect[256]; 52 int _zz_refuse[256]; 53 54 /* Local variables */ 55 static regex_t * re_include = NULL; 56 static regex_t * re_exclude = NULL; 57 58 /* Local prototypes */ 59 static void _zz_list_init(int *, char const *); 60 static void _zz_fd_init(void); 61 static void _zz_fd_fini(void); 62 63 /* Library initialisation shit */ 64 void _zz_init(void) 65 { 66 char *tmp; 67 68 tmp = getenv("ZZUF_DEBUG"); 69 if(tmp && *tmp == '1') 70 _zz_hasdebug = 1; 71 72 tmp = getenv("ZZUF_SEED"); 73 if(tmp && *tmp) 74 _zz_seed = atol(tmp); 75 76 tmp = getenv("ZZUF_RATIO"); 77 if(tmp && *tmp) 78 _zz_ratio = atof(tmp); 79 if(_zz_ratio < 0.0f) 80 _zz_ratio = 0.0f; 81 else if(_zz_ratio > 5.0f) 82 _zz_ratio = 5.0f; 83 84 tmp = getenv("ZZUF_PROTECT"); 85 if(tmp && *tmp) 86 _zz_list_init(_zz_protect, tmp); 87 88 tmp = getenv("ZZUF_REFUSE"); 89 if(tmp && *tmp) 90 _zz_list_init(_zz_refuse, tmp); 91 92 tmp = getenv("ZZUF_INCLUDE"); 93 if(tmp && *tmp) 94 { 95 re_include = malloc(sizeof(*re_include)); 96 regcomp(re_include, tmp, REG_EXTENDED); 97 } 98 99 tmp = getenv("ZZUF_EXCLUDE"); 100 if(tmp && *tmp) 101 { 102 re_exclude = malloc(sizeof(*re_exclude)); 103 regcomp(re_exclude, tmp, REG_EXTENDED); 104 } 105 106 tmp = getenv("ZZUF_SIGNAL"); 107 if(tmp && *tmp == '1') 108 _zz_signal = 1; 109 110 tmp = getenv("ZZUF_NETWORK"); 111 if(tmp && *tmp == '1') 112 _zz_network = 1; 113 114 _zz_fd_init(); 115 116 tmp = getenv("ZZUF_STDIN"); 117 if(tmp && *tmp == '1') 118 _zz_register(0); 119 120 _zz_load_fd(); 121 _zz_load_signal(); 122 _zz_load_stream(); 123 124 _zz_ready = 1; 125 126 debug("libzzuf initialised"); 127 } 128 129 /* Deinitialisation */ 130 void _zz_fini(void) 131 { 132 _zz_fd_fini(); 133 } 134 135 /* Byte list stuff */ 136 static void _zz_list_init(int *table, char const *list) 31 void _zz_readchars(int *table, char const *list) 137 32 { 138 33 static char const hex[] = "0123456789abcdef0123456789ABCDEF"; … … 200 95 } 201 96 202 /* File descriptor stuff */203 static struct files204 {205 int managed;206 uint64_t seed;207 uint64_t pos;208 /* Public stuff */209 struct fuzz fuzz;210 }211 *files;212 static int *fds;213 static int maxfd, nfiles;214 215 static void _zz_fd_init(void)216 {217 files = NULL;218 nfiles = 0;219 220 /* Start with one fd in the lookup table */221 fds = malloc(1 * sizeof(int));222 for(maxfd = 0; maxfd < 1; maxfd++)223 fds[maxfd] = -1;224 }225 226 static void _zz_fd_fini(void)227 {228 int i;229 230 for(i = 0; i < maxfd; i++)231 {232 if(!files[fds[i]].managed)233 continue;234 235 /* XXX: What are we supposed to do? If filedescriptors weren't236 * closed properly, there's a leak, but it's not our problem. */237 }238 239 free(files);240 free(fds);241 }242 243 int _zz_mustwatch(char const *file)244 {245 if(re_include && regexec(re_include, file, 0, NULL, 0) == REG_NOMATCH)246 return 0; /* not included: ignore */247 248 if(re_exclude && regexec(re_exclude, file, 0, NULL, 0) != REG_NOMATCH)249 return 0; /* excluded: ignore */250 251 return 1; /* default */252 }253 254 int _zz_iswatched(int fd)255 {256 if(fd < 0 || fd >= maxfd || fds[fd] == -1)257 return 0;258 259 return 1;260 }261 262 void _zz_register(int fd)263 {264 int i;265 266 if(fd < 0 || fd > 65535 || (fd < maxfd && fds[fd] != -1))267 return;268 269 while(fd >= maxfd)270 {271 fds = realloc(fds, 2 * maxfd * sizeof(int));272 for(i = maxfd; i < maxfd * 2; i++)273 fds[i] = -1;274 maxfd *= 2;275 }276 277 /* Find an empty slot */278 for(i = 0; i < nfiles; i++)279 if(files[i].managed == 0)280 break;281 282 /* No slot found, allocate memory */283 if(i == nfiles)284 {285 nfiles++;286 files = realloc(files, nfiles * sizeof(struct files));287 }288 289 files[i].managed = 1;290 files[i].pos = 0;291 files[i].fuzz.cur = -1;292 files[i].fuzz.data = malloc(CHUNKBYTES);293 #ifdef HAVE_FGETLN294 files[i].fuzz.tmp = NULL;295 #endif296 297 fds[fd] = i;298 }299 300 void _zz_unregister(int fd)301 {302 if(fd < 0 || fd >= maxfd || fds[fd] == -1)303 return;304 305 files[fds[fd]].managed = 0;306 free(files[fds[fd]].fuzz.data);307 #ifdef HAVE_FGETLN308 if(files[fds[fd]].fuzz.tmp)309 free(files[fds[fd]].fuzz.tmp);310 #endif311 312 fds[fd] = -1;313 }314 315 long int _zz_getpos(int fd)316 {317 if(fd < 0 || fd >= maxfd || fds[fd] == -1)318 return 0;319 320 return files[fds[fd]].pos;321 }322 323 void _zz_setpos(int fd, long int pos)324 {325 if(fd < 0 || fd >= maxfd || fds[fd] == -1)326 return;327 328 files[fds[fd]].pos = pos;329 }330 331 void _zz_addpos(int fd, long int off)332 {333 if(fd < 0 || fd >= maxfd || fds[fd] == -1)334 return;335 336 files[fds[fd]].pos += off;337 }338 339 struct fuzz *_zz_getfuzz(int fd)340 {341 if(fd < 0 || fd >= maxfd || fds[fd] == -1)342 return NULL;343 344 return &files[fds[fd]].fuzz;345 }346 -
zzuf/trunk/src/fd.c
r1591 r1613 25 25 # include <inttypes.h> 26 26 #endif 27 #include <stdio.h>28 #include <unistd.h>29 27 #include <stdlib.h> 30 #include <string.h>31 #include <fcntl.h>32 28 #include <regex.h> 33 29 34 #include <stdarg.h>35 #include <dlfcn.h>30 #include "libzzuf.h" 31 #include "fd.h" 36 32 37 #include "libzzuf.h" 38 #include "debug.h" 39 #include "load.h" 40 41 /* Global variables */ 42 int _zz_ready = 0; 43 int _zz_disabled = 0; 44 int _zz_hasdebug = 0; 45 float _zz_ratio = 0.004f; 46 int _zz_seed = 0; 47 int _zz_signal = 0; 48 int _zz_network = 0; 49 50 /* Global tables */ 51 int _zz_protect[256]; 52 int _zz_refuse[256]; 53 54 /* Local variables */ 55 static regex_t * re_include = NULL; 56 static regex_t * re_exclude = NULL; 57 58 /* Local prototypes */ 59 static void _zz_list_init(int *, char const *); 60 static void _zz_fd_init(void); 61 static void _zz_fd_fini(void); 62 63 /* Library initialisation shit */ 64 void _zz_init(void) 65 { 66 char *tmp; 67 68 tmp = getenv("ZZUF_DEBUG"); 69 if(tmp && *tmp == '1') 70 _zz_hasdebug = 1; 71 72 tmp = getenv("ZZUF_SEED"); 73 if(tmp && *tmp) 74 _zz_seed = atol(tmp); 75 76 tmp = getenv("ZZUF_RATIO"); 77 if(tmp && *tmp) 78 _zz_ratio = atof(tmp); 79 if(_zz_ratio < 0.0f) 80 _zz_ratio = 0.0f; 81 else if(_zz_ratio > 5.0f) 82 _zz_ratio = 5.0f; 83 84 tmp = getenv("ZZUF_PROTECT"); 85 if(tmp && *tmp) 86 _zz_list_init(_zz_protect, tmp); 87 88 tmp = getenv("ZZUF_REFUSE"); 89 if(tmp && *tmp) 90 _zz_list_init(_zz_refuse, tmp); 91 92 tmp = getenv("ZZUF_INCLUDE"); 93 if(tmp && *tmp) 94 { 95 re_include = malloc(sizeof(*re_include)); 96 regcomp(re_include, tmp, REG_EXTENDED); 97 } 98 99 tmp = getenv("ZZUF_EXCLUDE"); 100 if(tmp && *tmp) 101 { 102 re_exclude = malloc(sizeof(*re_exclude)); 103 regcomp(re_exclude, tmp, REG_EXTENDED); 104 } 105 106 tmp = getenv("ZZUF_SIGNAL"); 107 if(tmp && *tmp == '1') 108 _zz_signal = 1; 109 110 tmp = getenv("ZZUF_NETWORK"); 111 if(tmp && *tmp == '1') 112 _zz_network = 1; 113 114 _zz_fd_init(); 115 116 tmp = getenv("ZZUF_STDIN"); 117 if(tmp && *tmp == '1') 118 _zz_register(0); 119 120 _zz_load_fd(); 121 _zz_load_signal(); 122 _zz_load_stream(); 123 124 _zz_ready = 1; 125 126 debug("libzzuf initialised"); 127 } 128 129 /* Deinitialisation */ 130 void _zz_fini(void) 131 { 132 _zz_fd_fini(); 133 } 134 135 /* Byte list stuff */ 136 static void _zz_list_init(int *table, char const *list) 137 { 138 static char const hex[] = "0123456789abcdef0123456789ABCDEF"; 139 char const *tmp; 140 int a, b; 141 142 memset(table, 0, 256 * sizeof(int)); 143 144 for(tmp = list, a = b = -1; *tmp; tmp++) 145 { 146 int new; 147 148 if(*tmp == '\\' && tmp[1] == '\0') 149 new = '\\'; 150 else if(*tmp == '\\') 151 { 152 tmp++; 153 if(*tmp == 'n') 154 new = '\n'; 155 else if(*tmp == 'r') 156 new = '\r'; 157 else if(*tmp == 't') 158 new = '\t'; 159 else if(tmp[0] >= '0' && tmp[0] <= '7' && tmp[1] >= '0' 160 && tmp[1] <= '7' && tmp[2] >= '0' && tmp[2] <= '7') 161 { 162 new = tmp[2] - '0'; 163 new |= (int)(tmp[1] - '0') << 3; 164 new |= (int)(tmp[0] - '0') << 6; 165 tmp += 2; 166 } 167 else if((*tmp == 'x' || *tmp == 'X') 168 && tmp[1] && strchr(hex, tmp[1]) 169 && tmp[2] && strchr(hex, tmp[2])) 170 { 171 new = ((strchr(hex, tmp[1]) - hex) & 0xf) << 4; 172 new |= (strchr(hex, tmp[2]) - hex) & 0xf; 173 tmp += 2; 174 } 175 else 176 new = (unsigned char)*tmp; /* XXX: OK for \\, but what else? */ 177 } 178 else 179 new = (unsigned char)*tmp; 180 181 if(a != -1 && b == '-' && a <= new) 182 { 183 while(a <= new) 184 table[a++] = 1; 185 a = b = -1; 186 } 187 else 188 { 189 if(a != -1) 190 table[a] = 1; 191 a = b; 192 b = new; 193 } 194 } 195 196 if(a != -1) 197 table[a] = 1; 198 if(b != -1) 199 table[b] = 1; 200 } 33 regex_t * re_include = NULL; 34 regex_t * re_exclude = NULL; 201 35 202 36 /* File descriptor stuff */ … … 213 47 static int maxfd, nfiles; 214 48 215 staticvoid _zz_fd_init(void)49 void _zz_fd_init(void) 216 50 { 217 51 files = NULL; … … 224 58 } 225 59 226 staticvoid _zz_fd_fini(void)60 void _zz_fd_fini(void) 227 61 { 228 62 int i; -
zzuf/trunk/src/fuzz.c
r1595 r1613 26 26 #include <stdio.h> 27 27 #include <string.h> 28 #include <regex.h> 28 29 29 30 #include "libzzuf.h" … … 31 32 #include "random.h" 32 33 #include "fuzz.h" 34 #include "fd.h" 33 35 34 36 #define MAGIC1 0x33ea84f7 35 37 #define MAGIC2 0x783bc31f 38 39 static float _zz_ratio = 0.004f; 40 static int _zz_seed = 0; 41 42 void _zz_setseed(int seed) 43 { 44 _zz_seed = seed; 45 } 46 47 void _zz_setratio(float ratio) 48 { 49 _zz_ratio = ratio; 50 if(_zz_ratio < 0.0f) 51 _zz_ratio = 0.0f; 52 else if(_zz_ratio > 5.0f) 53 _zz_ratio = 5.0f; 54 } 36 55 37 56 void _zz_fuzz(int fd, uint8_t *buf, uint64_t len) -
zzuf/trunk/src/fuzz.h
r1523 r1613 17 17 */ 18 18 19 extern void _zz_setseed(int); 20 extern void _zz_setratio(float); 19 21 extern void _zz_fuzz(int, uint8_t *, uint64_t); 20 22 -
zzuf/trunk/src/libzzuf.c
r1566 r1613 38 38 #include "debug.h" 39 39 #include "load.h" 40 #include "chars.h" 41 #include "fd.h" 42 #include "fuzz.h" 40 43 41 44 /* Global variables */ … … 43 46 int _zz_disabled = 0; 44 47 int _zz_hasdebug = 0; 45 float _zz_ratio = 0.004f;46 int _zz_seed = 0;47 48 int _zz_signal = 0; 48 49 int _zz_network = 0; … … 51 52 int _zz_protect[256]; 52 53 int _zz_refuse[256]; 53 54 /* Local variables */55 static regex_t * re_include = NULL;56 static regex_t * re_exclude = NULL;57 58 /* Local prototypes */59 static void _zz_list_init(int *, char const *);60 static void _zz_fd_init(void);61 static void _zz_fd_fini(void);62 54 63 55 /* Library initialisation shit */ … … 72 64 tmp = getenv("ZZUF_SEED"); 73 65 if(tmp && *tmp) 74 _zz_se ed = atol(tmp);66 _zz_setseed(atol(tmp)); 75 67 76 68 tmp = getenv("ZZUF_RATIO"); 77 69 if(tmp && *tmp) 78 _zz_ratio = atof(tmp); 79 if(_zz_ratio < 0.0f) 80 _zz_ratio = 0.0f; 81 else if(_zz_ratio > 5.0f) 82 _zz_ratio = 5.0f; 70 _zz_setratio(atof(tmp)); 83 71 84 72 tmp = getenv("ZZUF_PROTECT"); 85 73 if(tmp && *tmp) 86 _zz_ list_init(_zz_protect, tmp);74 _zz_readchars(_zz_protect, tmp); 87 75 88 76 tmp = getenv("ZZUF_REFUSE"); 89 77 if(tmp && *tmp) 90 _zz_ list_init(_zz_refuse, tmp);78 _zz_readchars(_zz_refuse, tmp); 91 79 92 80 tmp = getenv("ZZUF_INCLUDE"); … … 133 121 } 134 122 135 /* Byte list stuff */136 static void _zz_list_init(int *table, char const *list)137 {138 static char const hex[] = "0123456789abcdef0123456789ABCDEF";139 char const *tmp;140 int a, b;141 142 memset(table, 0, 256 * sizeof(int));143 144 for(tmp = list, a = b = -1; *tmp; tmp++)145 {146 int new;147 148 if(*tmp == '\\' && tmp[1] == '\0')149 new = '\\';150 else if(*tmp == '\\')151 {152 tmp++;153 if(*tmp == 'n')154 new = '\n';155 else if(*tmp == 'r')156 new = '\r';157 else if(*tmp == 't')158 new = '\t';159 else if(tmp[0] >= '0' && tmp[0] <= '7' && tmp[1] >= '0'160 && tmp[1] <= '7' && tmp[2] >= '0' && tmp[2] <= '7')161 {162 new = tmp[2] - '0';163 new |= (int)(tmp[1] - '0') << 3;164 new |= (int)(tmp[0] - '0') << 6;165 tmp += 2;166 }167 else if((*tmp == 'x' || *tmp == 'X')168 && tmp[1] && strchr(hex, tmp[1])169 && tmp[2] && strchr(hex, tmp[2]))170 {171 new = ((strchr(hex, tmp[1]) - hex) & 0xf) << 4;172 new |= (strchr(hex, tmp[2]) - hex) & 0xf;173 tmp += 2;174 }175 else176 new = (unsigned char)*tmp; /* XXX: OK for \\, but what else? */177 }178 else179 new = (unsigned char)*tmp;180 181 if(a != -1 && b == '-' && a <= new)182 {183 while(a <= new)184 table[a++] = 1;185 a = b = -1;186 }187 else188 {189 if(a != -1)190 table[a] = 1;191 a = b;192 b = new;193 }194 }195 196 if(a != -1)197 table[a] = 1;198 if(b != -1)199 table[b] = 1;200 }201 202 /* File descriptor stuff */203 static struct files204 {205 int managed;206 uint64_t seed;207 uint64_t pos;208 /* Public stuff */209 struct fuzz fuzz;210 }211 *files;212 static int *fds;213 static int maxfd, nfiles;214 215 static void _zz_fd_init(void)216 {217 files = NULL;218 nfiles = 0;219 220 /* Start with one fd in the lookup table */221 fds = malloc(1 * sizeof(int));222 for(maxfd = 0; maxfd < 1; maxfd++)223 fds[maxfd] = -1;224 }225 226 static void _zz_fd_fini(void)227 {228 int i;229 230 for(i = 0; i < maxfd; i++)231 {232 if(!files[fds[i]].managed)233 continue;234 235 /* XXX: What are we supposed to do? If filedescriptors weren't236 * closed properly, there's a leak, but it's not our problem. */237 }238 239 free(files);240 free(fds);241 }242 243 int _zz_mustwatch(char const *file)244 {245 if(re_include && regexec(re_include, file, 0, NULL, 0) == REG_NOMATCH)246 return 0; /* not included: ignore */247 248 if(re_exclude && regexec(re_exclude, file, 0, NULL, 0) != REG_NOMATCH)249 return 0; /* excluded: ignore */250 251 return 1; /* default */252 }253 254 int _zz_iswatched(int fd)255 {256 if(fd < 0 || fd >= maxfd || fds[fd] == -1)257 return 0;258 259 return 1;260 }261 262 void _zz_register(int fd)263 {264 int i;265 266 if(fd < 0 || fd > 65535 || (fd < maxfd && fds[fd] != -1))267 return;268 269 while(fd >= maxfd)270 {271 fds = realloc(fds, 2 * maxfd * sizeof(int));272 for(i = maxfd; i < maxfd * 2; i++)273 fds[i] = -1;274 maxfd *= 2;275 }276 277 /* Find an empty slot */278 for(i = 0; i < nfiles; i++)279 if(files[i].managed == 0)280 break;281 282 /* No slot found, allocate memory */283 if(i == nfiles)284 {285 nfiles++;286 files = realloc(files, nfiles * sizeof(struct files));287 }288 289 files[i].managed = 1;290 files[i].pos = 0;291 files[i].fuzz.cur = -1;292 files[i].fuzz.data = malloc(CHUNKBYTES);293 #ifdef HAVE_FGETLN294 files[i].fuzz.tmp = NULL;295 #endif296 297 fds[fd] = i;298 }299 300 void _zz_unregister(int fd)301 {302 if(fd < 0 || fd >= maxfd || fds[fd] == -1)303 return;304 305 files[fds[fd]].managed = 0;306 free(files[fds[fd]].fuzz.data);307 #ifdef HAVE_FGETLN308 if(files[fds[fd]].fuzz.tmp)309 free(files[fds[fd]].fuzz.tmp);310 #endif311 312 fds[fd] = -1;313 }314 315 long int _zz_getpos(int fd)316 {317 if(fd < 0 || fd >= maxfd || fds[fd] == -1)318 return 0;319 320 return files[fds[fd]].pos;321 }322 323 void _zz_setpos(int fd, long int pos)324 {325 if(fd < 0 || fd >= maxfd || fds[fd] == -1)326 return;327 328 files[fds[fd]].pos = pos;329 }330 331 void _zz_addpos(int fd, long int off)332 {333 if(fd < 0 || fd >= maxfd || fds[fd] == -1)334 return;335 336 files[fds[fd]].pos += off;337 }338 339 struct fuzz *_zz_getfuzz(int fd)340 {341 if(fd < 0 || fd >= maxfd || fds[fd] == -1)342 return NULL;343 344 return &files[fds[fd]].fuzz;345 }346 -
zzuf/trunk/src/libzzuf.h
r1566 r1613 39 39 extern int _zz_disabled; 40 40 extern int _zz_hasdebug; 41 extern float _zz_ratio;42 extern int _zz_seed;43 41 extern int _zz_signal; 44 42 extern int _zz_network; … … 52 50 extern void _zz_fini(void) __attribute__((destructor)); 53 51 54 /* File descriptor handling */55 extern int _zz_mustwatch(char const *);56 extern int _zz_iswatched(int);57 extern void _zz_register(int);58 extern void _zz_unregister(int);59 extern long int _zz_getpos(int);60 extern void _zz_setpos(int, long int);61 extern void _zz_addpos(int, long int);62 extern struct fuzz *_zz_getfuzz(int);63 -
zzuf/trunk/src/load-fd.c
r1585 r1613 32 32 #include <string.h> 33 33 #include <dlfcn.h> 34 #include <regex.h> 34 35 35 36 #include <sys/types.h> … … 44 45 #include "fuzz.h" 45 46 #include "load.h" 47 #include "fd.h" 46 48 47 49 /* Library functions that we divert */ -
zzuf/trunk/src/load-signal.c
r1543 r1613 29 29 #include <stdlib.h> 30 30 #include <dlfcn.h> 31 #include <regex.h> 31 32 32 33 #include <string.h> -
zzuf/trunk/src/load-stream.c
r1611 r1613 28 28 #include <stdlib.h> 29 29 #include <dlfcn.h> 30 #include <regex.h> 30 31 31 32 #include <stdio.h> … … 39 40 #include "fuzz.h" 40 41 #include "load.h" 42 #include "fd.h" 41 43 42 44 #if !defined __FreeBSD__ && !defined __OpenBSD__ -
zzuf/trunk/src/zzuf.c
r1578 r1613 38 38 #include <sys/wait.h> 39 39 40 #include "libzzuf.h" 40 41 #include "random.h" 41 #include "libzzuf.h" 42 #include "chars.h" 43 #include "fd.h" 44 #include "fuzz.h" 42 45 43 46 static void spawn_child(char **); … … 53 56 #endif 54 57 58 /* Global tables */ 59 int _zz_protect[256]; 60 int _zz_refuse[256]; 61 55 62 static struct child_list 56 63 { … … 91 98 { 92 99 char **newargv; 93 char *parser, *include = NULL, *exclude = NULL;100 char *parser, *include, *exclude, *protect, *refuse; 94 101 int i, cmdline = 0; 102 103 include = exclude = protect = refuse = NULL; 95 104 96 105 #if defined(HAVE_GETOPT_H) … … 173 182 break; 174 183 case 'P': /* --protect */ 175 setenv("ZZUF_PROTECT", optarg, 1);184 protect = optarg; 176 185 break; 177 186 case 'q': /* --quiet */ … … 180 189 case 'r': /* --ratio */ 181 190 setenv("ZZUF_RATIO", optarg, 1); 191 _zz_setratio(atof(optarg)); 182 192 break; 183 193 case 'R': /* --refuse */ 184 setenv("ZZUF_REFUSE", optarg, 1);194 refuse = optarg; 185 195 break; 186 196 case 's': /* --seed */ 187 197 parser = strchr(optarg, ':'); 188 seed = atoi(optarg);198 _zz_setseed(seed = atol(optarg)); 189 199 endseed = parser ? atoi(parser + 1) : seed + 1; 190 200 break; … … 212 222 #endif 213 223 224 /* If asked to read from the standard input */ 214 225 if(optind >= argc) 215 226 { 216 printf("%s: missing argument\n", argv[0]); 217 printf(MOREINFO, argv[0]); 218 return EXIT_FAILURE; 227 if(endseed != seed + 1) 228 { 229 printf("%s: seed ranges are incompatible with stdin fuzzing\n", 230 argv[0]); 231 printf(MOREINFO, argv[0]); 232 return EXIT_FAILURE; 233 } 234 235 if(protect) 236 _zz_readchars(_zz_protect, protect); 237 if(refuse) 238 _zz_readchars(_zz_refuse, protect); 239 240 _zz_fd_init(); 241 _zz_register(0); 242 243 for(;;) 244 { 245 uint8_t buf[12]; 246 int ret = fread(buf, 1, 12, stdin); 247 if(ret <= 0) 248 break; 249 250 _zz_fuzz(0, buf, ret); 251 _zz_addpos(0, ret); 252 253 fwrite(buf, 1, ret, stdout); 254 } 255 256 _zz_unregister(0); 257 _zz_fd_fini(); 258 259 return EXIT_SUCCESS; 219 260 } 220 261 … … 238 279 if(exclude) 239 280 setenv("ZZUF_EXCLUDE", exclude, 1); 281 if(protect) 282 setenv("ZZUF_PROTECT", protect, 1); 283 if(refuse) 284 setenv("ZZUF_REFUSE", refuse, 1); 240 285 241 286 /* Allocate memory for children handling */
Note: See TracChangeset
for help on using the changeset viewer.