source: zzuf/trunk/src/libzzuf/lib-signal.c @ 4373

Last change on this file since 4373 was 4373, checked in by Sam Hocevar, 11 years ago

Revert any potential overriding macro before declaring a new function.

  • Property svn:keywords set to Id
File size: 2.9 KB
Line 
1/*
2 *  zzuf - general purpose fuzzer
3 *  Copyright (c) 2006-2010 Sam Hocevar <sam@hocevar.net>
4 *                All Rights Reserved
5 *
6 *  This program is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13/*
14 *  load-signal.c: loaded signal functions
15 */
16
17#include "config.h"
18
19/* Needed for sighandler_t on glibc systems */
20#define _GNU_SOURCE
21/* Needed for struct sigaction on HP-UX */
22#define _INCLUDE_POSIX_SOURCE
23/* Needed for struct sigaction on OpenSolaris */
24#define __EXTENSIONS__
25
26#if defined HAVE_STDINT_H
27#   include <stdint.h>
28#elif defined HAVE_INTTYPES_H
29#   include <inttypes.h>
30#endif
31#include <stdlib.h>
32
33#include <string.h>
34#include <signal.h>
35
36#include "libzzuf.h"
37#include "lib-load.h"
38#include "debug.h"
39#include "fuzz.h"
40
41#if defined HAVE_SIGHANDLER_T
42#   define SIG_T sighandler_t
43#elif defined HAVE_SIG_T
44#   define SIG_T sig_t
45#else
46    typedef void (*SIG_T) (int);
47#endif
48
49/* Library functions that we divert */
50static SIG_T (*ORIG(signal))    (int signum, SIG_T handler);
51#if defined HAVE_SIGACTION
52static int   (*ORIG(sigaction)) (int signum, const struct sigaction *act,
53                                 struct sigaction *oldact);
54#endif
55/* Local functions */
56static int isfatal(int signum);
57
58static int isfatal(int signum)
59{
60    switch(signum)
61    {
62        case SIGABRT:
63        case SIGFPE:
64        case SIGILL:
65#if defined SIGQUIT
66        case SIGQUIT:
67#endif
68        case SIGSEGV:
69#if defined SIGTRAP
70        case SIGTRAP:
71#endif
72#if defined SIGSYS
73        case SIGSYS:
74#endif
75#if defined SIGEMT
76        case SIGEMT:
77#endif
78#if defined SIGBUS
79        case SIGBUS:
80#endif
81#if defined SIGXCPU
82        case SIGXCPU:
83#endif
84#if defined SIGXFSZ
85        case SIGXFSZ:
86#endif
87            return 1;
88        default:
89            return 0;
90    }
91}
92
93#undef signal
94SIG_T NEW(signal)(int signum, SIG_T handler)
95{
96    SIG_T ret;
97
98    LOADSYM(signal);
99
100    if(!_zz_signal)
101        return ORIG(signal)(signum, handler);
102
103    ret = ORIG(signal)(signum, isfatal(signum) ? SIG_DFL : handler);
104
105    debug("%s(%i, %p) = %p", __func__, signum, handler, ret);
106
107    return ret;
108}
109
110#if defined HAVE_SIGACTION
111#undef sigaction
112int NEW(sigaction)(int signum, const struct sigaction *act,
113                   struct sigaction *oldact)
114{
115    int ret;
116
117    LOADSYM(sigaction);
118
119    if(!_zz_signal)
120        return ORIG(sigaction)(signum, act, oldact);
121
122    if(act && isfatal(signum))
123    {
124        struct sigaction newact;
125        memcpy(&newact, act, sizeof(struct sigaction));
126        newact.sa_handler = SIG_DFL;
127        ret = ORIG(sigaction)(signum, &newact, oldact);
128    }
129    else
130        ret = ORIG(sigaction)(signum, act, oldact);
131
132    debug("%s(%i, %p, %p) = %i", __func__, signum, act, oldact, ret);
133
134    return ret;
135}
136#endif
137
Note: See TracBrowser for help on using the repository browser.