source: zzuf/trunk/src/load-signal.c @ 1621

Last change on this file since 1621 was 1621, checked in by Sam Hocevar, 14 years ago
  • Factor regex stuff into fd.c, so that <regex.h> isn’t needed otherwhere.
  • Property svn:keywords set to Id
File size: 2.7 KB
Line 
1/*
2 *  zzuf - general purpose fuzzer
3 *  Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
4 *                All Rights Reserved
5 *
6 *  $Id: load-signal.c 1621 2007-01-07 21:14:26Z 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 *  load-signal.c: loaded signal functions
17 */
18
19#include "config.h"
20
21/* needed for sighandler_t */
22#define _GNU_SOURCE
23
24#if defined HAVE_STDINT_H
25#   include <stdint.h>
26#elif defined HAVE_INTTYPES_H
27#   include <inttypes.h>
28#endif
29#include <stdlib.h>
30#include <dlfcn.h>
31
32#include <string.h>
33#include <signal.h>
34
35#include "libzzuf.h"
36#include "debug.h"
37#include "fuzz.h"
38#include "load.h"
39
40#if defined HAVE_SIGHANDLER_T
41#   define SIG_T sighandler_t
42#elif defined HAVE_SIG_T
43#   define SIG_T sig_t
44#endif
45
46/* Library functions that we divert */
47static SIG_T (*signal_orig)    (int signum, SIG_T handler);
48static int   (*sigaction_orig) (int signum, const struct sigaction *act,
49                                struct sigaction *oldact);
50/* Local functions */
51static int isfatal(int signum);
52
53void _zz_load_signal(void)
54{
55    LOADSYM(signal);
56    LOADSYM(sigaction);
57}
58
59static int isfatal(int signum)
60{
61    switch(signum)
62    {
63        case SIGABRT:
64        case SIGFPE:
65        case SIGILL:
66        case SIGQUIT:
67        case SIGSEGV:
68        case SIGTRAP:
69#ifdef SIGSYS
70        case SIGSYS:
71#endif
72#ifdef SIGEMT
73        case SIGEMT:
74#endif
75#ifdef SIGBUS
76        case SIGBUS:
77#endif
78#ifdef SIGXCPU
79        case SIGXCPU:
80#endif
81#ifdef SIGXFSZ
82        case SIGXFSZ:
83#endif
84            return 1;
85        default:
86            return 0;
87    }
88}
89
90SIG_T signal(int signum, SIG_T handler)
91{
92    SIG_T ret;
93
94    if(!_zz_ready)
95        LOADSYM(signal);
96
97    if(!_zz_signal)
98        return signal_orig(signum, handler);
99
100    ret = signal_orig(signum, isfatal(signum) ? SIG_DFL : handler);
101
102    debug("signal(%i, %p) = %p", signum, handler, ret);
103
104    return ret;
105}
106
107int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
108{
109    int ret;
110
111    if(!_zz_ready)
112        LOADSYM(sigaction);
113
114    if(!_zz_signal)
115        return sigaction_orig(signum, act, oldact);
116
117    if(act && isfatal(signum))
118    {
119        struct sigaction newact;
120        memcpy(&newact, act, sizeof(struct sigaction));
121        newact.sa_handler = SIG_DFL;
122        ret = sigaction_orig(signum, &newact, oldact);
123    }
124    else
125        ret = sigaction_orig(signum, act, oldact);
126
127    debug("sigaction(%i, %p, %p) = %i", signum, act, oldact, ret);
128
129    return ret;
130}
131
Note: See TracBrowser for help on using the repository browser.