0001-Reset-SIGFPE-handler-after-plperl-initialization.patch
text/x-patch
Filename: 0001-Reset-SIGFPE-handler-after-plperl-initialization.patch
Type: text/x-patch
Part: 0
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch 0001
Subject: Reset SIGFPE handler after plperl initialization
| File | + | − |
|---|---|---|
| src/pl/plperl/plperl.c | 16 | 0 |
From c5583861a98c6e5c26961d6346c5b5abc699f90d Mon Sep 17 00:00:00 2001 From: Andres Freund <andres@anarazel.de> Date: Wed, 5 Sep 2012 16:04:41 +0200 Subject: [PATCH] Reset SIGFPE handler after plperl initialization Unfortunately perl resets the sigfpe handler to SIG_IGN which is bad for two reasons: First, we don't get a nice error message anymore if a SIGFPE is generated via math on the sql level, secondly setting SIGFPE to SIG_IGN is strongly discouraged by posix and invokes undefined behaviour according to it. At least linux defines this undefined behaviour as resetting the SIGFPE handler and killing the triggering process. In perl bug 114574 the perl developers agree that the correct approach is to just reset the SIGFPE handler. On some platforms this fixes a server crash with: SELECT (-(2^31))::int/-1; --- src/pl/plperl/plperl.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c index b31e965..f4b2fa9 100644 --- a/src/pl/plperl/plperl.c +++ b/src/pl/plperl/plperl.c @@ -28,6 +28,7 @@ #include "nodes/makefuncs.h" #include "parser/parse_type.h" #include "storage/ipc.h" +#include "tcop/tcopprot.h" #include "utils/builtins.h" #include "utils/fmgroids.h" #include "utils/guc.h" @@ -743,6 +744,21 @@ plperl_init_interp(void) perl_sys_init_done = 1; /* quiet warning if PERL_SYS_INIT3 doesn't use the third argument */ dummy_env[0] = NULL; + + /* + * Unfortunately perl resets the sigfpe handler to SIG_IGN which is + * bad for two reasons: First, we don't get a nice error message + * anymore if a SIGFPE is generated via math on the sql level, + * secondly setting SIGFPE to SIG_IGN is strongly discouraged by + * posix and invokes undefined behaviour according to it. + * At least linux defines this undefined behaviour as resetting the + * SIGFPE handler and killing the triggering process. + * + * In perl bug 114574 the perl developers agree that the correct + * approach is to just reset the SIGFPE handler. + */ + pqsignal(SIGFPE, FloatExceptionHandler); + } } #endif -- 1.7.10.4