1 | /* |
---|
2 | * zzuf - general purpose fuzzer |
---|
3 | * Copyright (c) 2006 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: libzzuf.c 1490 2006-12-15 18:48:24Z sam $ |
---|
7 | * |
---|
8 | * This program is free software. It comes without any warranty, to |
---|
9 | * the extent permitted by applicable law. You can redistribute it |
---|
10 | * and/or modify it under the terms of the Do What The Fuck You Want |
---|
11 | * To Public License, Version 2, as published by Sam Hocevar. See |
---|
12 | * http://sam.zoy.org/wtfpl/COPYING for more details. |
---|
13 | */ |
---|
14 | |
---|
15 | /* |
---|
16 | * libzzuf.c: preloaded wrapper library |
---|
17 | */ |
---|
18 | |
---|
19 | #include "config.h" |
---|
20 | #define _GNU_SOURCE |
---|
21 | |
---|
22 | #if defined HAVE_STDINT_H |
---|
23 | # include <stdint.h> |
---|
24 | #elif defined HAVE_INTTYPES_H |
---|
25 | # include <inttypes.h> |
---|
26 | #endif |
---|
27 | #include <stdio.h> |
---|
28 | #include <unistd.h> |
---|
29 | #include <stdlib.h> |
---|
30 | #include <fcntl.h> |
---|
31 | #include <regex.h> |
---|
32 | |
---|
33 | #include <stdarg.h> |
---|
34 | #include <dlfcn.h> |
---|
35 | |
---|
36 | #include "libzzuf.h" |
---|
37 | #include "debug.h" |
---|
38 | #include "preload.h" |
---|
39 | |
---|
40 | /* Global variables */ |
---|
41 | int _zzuf_ready = 0; |
---|
42 | int _zzuf_debug = 0; |
---|
43 | int _zzuf_seed = 0; |
---|
44 | float _zzuf_ratio = 0.004f; |
---|
45 | regex_t * _zzuf_include = NULL; |
---|
46 | regex_t * _zzuf_exclude = NULL; |
---|
47 | |
---|
48 | #define MAXFD 1024 |
---|
49 | struct zzuf files[MAXFD]; |
---|
50 | |
---|
51 | /* Library initialisation shit */ |
---|
52 | void zzuf_init(void) |
---|
53 | { |
---|
54 | char *tmp; |
---|
55 | int i; |
---|
56 | |
---|
57 | tmp = getenv("ZZUF_DEBUG"); |
---|
58 | if(tmp && *tmp) |
---|
59 | _zzuf_debug = 1; |
---|
60 | |
---|
61 | tmp = getenv("ZZUF_SEED"); |
---|
62 | if(tmp && *tmp) |
---|
63 | _zzuf_seed = atol(tmp); |
---|
64 | |
---|
65 | tmp = getenv("ZZUF_RATIO"); |
---|
66 | if(tmp && *tmp) |
---|
67 | _zzuf_ratio = atof(tmp); |
---|
68 | if(_zzuf_ratio < 0.0f) |
---|
69 | _zzuf_ratio = 0.0f; |
---|
70 | else if(_zzuf_ratio > 5.0f) |
---|
71 | _zzuf_ratio = 5.0f; |
---|
72 | |
---|
73 | tmp = getenv("ZZUF_INCLUDE"); |
---|
74 | if(tmp && *tmp) |
---|
75 | { |
---|
76 | _zzuf_include = malloc(sizeof(*_zzuf_include)); |
---|
77 | regcomp(_zzuf_include, tmp, 0); |
---|
78 | } |
---|
79 | |
---|
80 | tmp = getenv("ZZUF_EXCLUDE"); |
---|
81 | if(tmp && *tmp) |
---|
82 | { |
---|
83 | _zzuf_exclude = malloc(sizeof(*_zzuf_exclude)); |
---|
84 | regcomp(_zzuf_exclude, tmp, 0); |
---|
85 | } |
---|
86 | |
---|
87 | for(i = 0; i < MAXFD; i++) |
---|
88 | files[i].managed = 0; |
---|
89 | |
---|
90 | zzuf_preload_libc(); |
---|
91 | |
---|
92 | _zzuf_ready = 1; |
---|
93 | |
---|
94 | debug("libzzuf initialised"); |
---|
95 | } |
---|
96 | |
---|
97 | /* Deinitialisation */ |
---|
98 | void zzuf_fini(void) |
---|
99 | { |
---|
100 | int i; |
---|
101 | |
---|
102 | for(i = 0; i < MAXFD; i++) |
---|
103 | { |
---|
104 | if(!files[i].managed) |
---|
105 | continue; |
---|
106 | |
---|
107 | /* TODO */ |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|