]> granicus.if.org Git - sudo/commitdiff
Fix handling of real-time signals.
authorTodd C. Miller <Todd.Miller@sudo.ws>
Mon, 19 Aug 2019 14:36:30 +0000 (08:36 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Mon, 19 Aug 2019 14:36:30 +0000 (08:36 -0600)
lib/util/sig2str.c
lib/util/str2sig.c

index 23237fa533fa1daf5e4dc1d44315a3b6fe559803..6049b1b2c63ed2234a27852df2b9cd15d1f44b31 100644 (file)
@@ -62,9 +62,22 @@ int
 sudo_sig2str(int signo, char *signame)
 {
 #if defined(SIGRTMIN) && defined(SIGRTMAX)
-    /* Realtime signal support as per Solaris. */
+    /* Realtime signal support. */
     if (signo >= SIGRTMIN && signo <= SIGRTMAX) {
-       (void)snprintf(signame, SIG2STR_MAX, "RTMIN+%d", (signo - SIGRTMIN));
+       const long rtmax = sysconf(_SC_RTSIG_MAX);
+       if (rtmax > 0) {
+           if (signo == SIGRTMIN) {
+               strlcpy(signame, "RTMIN", SIG2STR_MAX);
+           } else if (signo == SIGRTMAX) {
+               strlcpy(signame, "RTMAX", SIG2STR_MAX);
+           } else if (signo <= SIGRTMIN + (rtmax / 2) - 1) {
+               (void)snprintf(signame, SIG2STR_MAX, "RTMIN+%d",
+                   (signo - SIGRTMIN));
+           } else {
+               (void)snprintf(signame, SIG2STR_MAX, "RTMAX-%d",
+                   (SIGRTMAX - signo));
+           }
+       }
        return 0;
     }
 #endif
index 236348b6a2d23155cbe1f6fa5ab79c9391f7495d..68b12c6d26cc5283672e7c0003645805143199d9 100644 (file)
@@ -36,8 +36,9 @@
 #ifdef HAVE_STRINGS_H
 # include <strings.h>
 #endif /* HAVE_STRINGS_H */
-#include <signal.h>
 #include <ctype.h>
+#include <signal.h>
+#include <unistd.h>
 
 #include "sudo_compat.h"
 
@@ -117,9 +118,14 @@ sudo_str2sig(const char *signame, int *result)
                return 0;
            }
            if (signame[5] == '+') {
-               if (signame[6] == '1' || signame[6] == '2' || signame[6] == '3') {
-                   *result = SIGRTMIN + (signame[6] - '0');
-                   return 0;
+               if (isdigit((unsigned char)signame[6])) {
+                   const long rtmax = sysconf(_SC_RTSIG_MAX);
+                   const int off = signame[6] - '0';
+
+                   if (rtmax > 0 && off < rtmax / 2) {
+                       *result = SIGRTMIN + off;
+                       return 0;
+                   }
                }
            }
        }
@@ -131,9 +137,14 @@ sudo_str2sig(const char *signame, int *result)
                return 0;
            }
            if (signame[5] == '-') {
-               if (signame[6] == '1' || signame[6] == '2' || signame[6] == '3') {
-                   *result = SIGRTMAX - (signame[6] - '0');
-                   return 0;
+               if (isdigit((unsigned char)signame[6])) {
+                   const long rtmax = sysconf(_SC_RTSIG_MAX);
+                   const int off = signame[6] - '0';
+
+                   if (rtmax > 0 && off < rtmax / 2) {
+                       *result = SIGRTMAX - off;
+                       return 0;
+                   }
                }
            }
        }
@@ -141,10 +152,12 @@ sudo_str2sig(const char *signame, int *result)
        break;
     }
 
-    for (signo = 0; signo < NSIG; signo++) {
-       if (strcmp(signame, sudo_sys_signame[signo]) == 0) {
-           *result = signo;
-           return 0;
+    for (signo = 1; signo < NSIG; signo++) {
+       if (sudo_sys_signame[signo] != NULL) {
+           if (strcmp(signame, sudo_sys_signame[signo]) == 0) {
+               *result = signo;
+               return 0;
+           }
        }
     }