From: Arran Cudbard-Bell Date: Wed, 7 Feb 2018 16:12:07 +0000 (+0000) Subject: Check permissions last, right before we call the panic action X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4e01a5ed012e5c0903f6651303d2a7f692d35cf1;p=thirdparty%2Ffreeradius-server.git Check permissions last, right before we call the panic action --- diff --git a/src/lib/util/debug.c b/src/lib/util/debug.c index cf1eccbaa3a..5ced2a40a2c 100644 --- a/src/lib/util/debug.c +++ b/src/lib/util/debug.c @@ -639,14 +639,14 @@ static int fr_fault_check_permissions(void) */ NEVER_RETURNS void fr_fault(int sig) { - char cmd[sizeof(panic_action) + 20]; - char *out = cmd; - size_t left = sizeof(cmd), ret; + char cmd[sizeof(panic_action) + 20]; + char *out = cmd; + size_t left = sizeof(cmd), ret; - char const *p = panic_action; - char const *q; + char const *p = panic_action; + char const *q; - int code; + int code; /* * If a debugger is attached, we don't want to run the panic action, @@ -666,14 +666,6 @@ NEVER_RETURNS void fr_fault(int sig) FR_FAULT_LOG("CAUGHT SIGNAL: %s", strsignal(sig)); - /* - * Check for administrator sanity. - */ - if (fr_fault_check_permissions() < 0) { - FR_FAULT_LOG("Refusing to execute panic action: %s", fr_strerror()); - goto finish; - } - /* * Run the callback if one was registered */ @@ -706,6 +698,14 @@ NEVER_RETURNS void fr_fault(int sig) goto finish; } + /* + * Check for administrator sanity. + */ + if (fr_fault_check_permissions() < 0) { + FR_FAULT_LOG("Refusing to execute panic action: %s", fr_strerror()); + goto finish; + } + /* Substitute %p for the current PID (useful for attaching a debugger) */ while ((q = strstr(p, "%p"))) { out += ret = snprintf(out, left, "%.*s%d", (int) (q - p), p, (int) getpid()); @@ -760,17 +760,16 @@ NEVER_RETURNS void fr_fault(int sig) fr_exit_now(128 + sig); } - finish: /* * (Re-)Raise the signal, so that if we're running under - * a debugger, the debugger can break when it receives - * the signal. + * a debugger. + * + * This allows debuggers to function normally and catch + * fatal signals. */ - fr_unset_signal(sig); /* Make sure we don't get into a loop */ - + fr_unset_signal(sig); /* Make sure we don't get into a loop */ raise(sig); - fr_exit_now(128 + sig); /* Function marked as noreturn */ }