source: zzuf/trunk/src/libzzuf.c @ 1613

Last change on this file since 1613 was 1613, checked in by Sam Hocevar, 14 years ago
  • If no argument is given, just fuzz standard input.
  • Property svn:keywords set to Id
File size: 2.4 KB
Line 
1/*
2 *  zzuf - general purpose fuzzer
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: libzzuf.c 1613 2007-01-07 18:18:50Z 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 <string.h>
31#include <fcntl.h>
32#include <regex.h>
33
34#include <stdarg.h>
35#include <dlfcn.h>
36
37#include "libzzuf.h"
38#include "debug.h"
39#include "load.h"
40#include "chars.h"
41#include "fd.h"
42#include "fuzz.h"
43
44/* Global variables */
45int   _zz_ready    = 0;
46int   _zz_disabled = 0;
47int   _zz_hasdebug = 0;
48int   _zz_signal   = 0;
49int   _zz_network  = 0;
50
51/* Global tables */
52int   _zz_protect[256];
53int   _zz_refuse[256];
54
55/* Library initialisation shit */
56void _zz_init(void)
57{
58    char *tmp;
59
60    tmp = getenv("ZZUF_DEBUG");
61    if(tmp && *tmp == '1')
62        _zz_hasdebug = 1;
63
64    tmp = getenv("ZZUF_SEED");
65    if(tmp && *tmp)
66        _zz_setseed(atol(tmp));
67
68    tmp = getenv("ZZUF_RATIO");
69    if(tmp && *tmp)
70        _zz_setratio(atof(tmp));
71
72    tmp = getenv("ZZUF_PROTECT");
73    if(tmp && *tmp)
74        _zz_readchars(_zz_protect, tmp);
75
76    tmp = getenv("ZZUF_REFUSE");
77    if(tmp && *tmp)
78        _zz_readchars(_zz_refuse, tmp);
79
80    tmp = getenv("ZZUF_INCLUDE");
81    if(tmp && *tmp)
82    {
83        re_include = malloc(sizeof(*re_include));
84        regcomp(re_include, tmp, REG_EXTENDED);
85    }
86
87    tmp = getenv("ZZUF_EXCLUDE");
88    if(tmp && *tmp)
89    {
90        re_exclude = malloc(sizeof(*re_exclude));
91        regcomp(re_exclude, tmp, REG_EXTENDED);
92    }
93
94    tmp = getenv("ZZUF_SIGNAL");
95    if(tmp && *tmp == '1')
96        _zz_signal = 1;
97
98    tmp = getenv("ZZUF_NETWORK");
99    if(tmp && *tmp == '1')
100        _zz_network = 1;
101
102    _zz_fd_init();
103
104    tmp = getenv("ZZUF_STDIN");
105    if(tmp && *tmp == '1')
106        _zz_register(0);
107
108    _zz_load_fd();
109    _zz_load_signal();
110    _zz_load_stream();
111
112    _zz_ready = 1;
113
114    debug("libzzuf initialised");
115}
116
117/* Deinitialisation */
118void _zz_fini(void)
119{
120    _zz_fd_fini();
121}
122
Note: See TracBrowser for help on using the repository browser.