]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Check permissions last, right before we call the panic action
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 7 Feb 2018 16:12:07 +0000 (16:12 +0000)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Wed, 7 Feb 2018 17:50:57 +0000 (17:50 +0000)
src/lib/util/debug.c

index cf1eccbaa3afdd4f309854b17dd7f1de0e001016..5ced2a40a2ca56c0506d9271688c4394d36be921 100644 (file)
@@ -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 */
 }