From 48066e0dbd47ec0e9c99f9d920925d95216d0564 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 19 Aug 2019 08:36:53 -0600 Subject: [PATCH] SIGIOT and SIGABRT are aliases on BSD systems. --- lib/util/str2sig.c | 132 ++++++++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/lib/util/str2sig.c b/lib/util/str2sig.c index 68b12c6d2..63ea642cc 100644 --- a/lib/util/str2sig.c +++ b/lib/util/str2sig.c @@ -56,14 +56,43 @@ 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) { -- 2.40.0