]> granicus.if.org Git - sudo/commitdiff
SIGIOT and SIGABRT are aliases on BSD systems.
authorTodd C. Miller <Todd.Miller@sudo.ws>
Mon, 19 Aug 2019 14:36:53 +0000 (08:36 -0600)
committerTodd C. Miller <Todd.Miller@sudo.ws>
Mon, 19 Aug 2019 14:36:53 +0000 (08:36 -0600)
lib/util/str2sig.c

index 68b12c6d26cc5283672e7c0003645805143199d9..63ea642cc30b829373ea416726a8134411d11836 100644 (file)
 extern const char *const sudo_sys_signame[NSIG];
 #endif
 
+/*
+ * Many systems use aliases for source backward compatibility.
+ */
+static struct sigalias {
+    const char *name;
+    int number;
+} sigaliases[] = {
+#ifdef SIGABRT
+    { "ABRT", SIGABRT },
+#endif
+#ifdef SIGCLD
+    { "CLD",  SIGCLD },
+#endif
+#ifdef SIGIO
+    { "IO",   SIGIO },
+#endif
+#ifdef SIGIOT
+    { "IOT",  SIGIOT },
+#endif
+#ifdef SIGLOST
+    { "LOST", SIGLOST },
+#endif
+#ifdef SIGPOLL
+    { "POLL", SIGPOLL },
+#endif
+    { NULL, -1 }
+};
+
 /*
  * Translate signal name to number.
  */
 int
 sudo_str2sig(const char *signame, int *result)
 {
-    int signo;
+    struct sigalias *alias;
     const char *errstr;
+    int signo;
 
     /* Could be a signal number encoded as a string. */
     if (isdigit((unsigned char)signame[0])) {
@@ -74,84 +103,55 @@ sudo_str2sig(const char *signame, int *result)
        return 0;
     }
 
-    /* Special cases. */
-    switch (signame[0]) {
-    case 'C':
-       /* support both SIGCLD and SIGCHLD */
-#ifdef SIGCLD
-       if (strcmp(signame, "CLD") == 0) {
-           *result = SIGCLD;
-           return 0;
-       }
-#endif
-#ifdef SIGCHLD
-       if (strcmp(signame, "CHLD") == 0) {
-           *result = SIGCHLD;
-           return 0;
-       }
-#endif
-       break;
-#ifdef SIGIO
-    case 'I':
-       /* support both SIGIO and SIGPOLL */
-       if (strcmp(signame, "IO") == 0) {
-           *result = SIGIO;
-           return 0;
-       }
-       break;
-#endif
-#ifdef SIGPOLL
-    case 'P':
-       /* support both SIGIO and SIGPOLL */
-       if (strcmp(signame, "POLL") == 0) {
-           *result = SIGPOLL;
+    /* Check real-time signals. */
+#if defined(SIGRTMIN)
+    if (strncmp(signame, "RTMIN", 5) == 0) {
+       if (signame[5] == '\0') {
+           *result = SIGRTMIN;
            return 0;
        }
-       break;
-#endif
-    case 'R':
-       /* real-time signals */
-#if defined(SIGRTMIN)
-       if (strncmp(signame, "RTMIN", 5) == 0) {
-           if (signame[5] == '\0') {
-               *result = SIGRTMIN;
-               return 0;
-           }
-           if (signame[5] == '+') {
-               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;
-                   }
+       if (signame[5] == '+') {
+           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;
                }
            }
        }
+    }
 #endif
 #if defined(SIGRTMAX)
-       if (strncmp(signame, "RTMAX", 5) == 0) {
-           if (signame[5] == '\0') {
-               *result = SIGRTMAX;
-               return 0;
-           }
-           if (signame[5] == '-') {
-               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;
-                   }
+    if (strncmp(signame, "RTMAX", 5) == 0) {
+       if (signame[5] == '\0') {
+           *result = SIGRTMAX;
+           return 0;
+       }
+       if (signame[5] == '-') {
+           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;
                }
            }
        }
+    }
 #endif
-       break;
+
+    /* Check aliases. */
+    for (alias = sigaliases; alias->name != NULL; alias++) {
+       if (strcmp(signame, alias->name) == 0) {
+           *result = alias->number;
+           return 0;
+       }
     }
 
+    /* Check sys_signame[]. */
     for (signo = 1; signo < NSIG; signo++) {
        if (sudo_sys_signame[signo] != NULL) {
            if (strcmp(signame, sudo_sys_signame[signo]) == 0) {