Use sigabbrev_np(3) to access signal abbreviations if supported.

glibc-2.32 has removed sys_sigabbrev[], we can use sigabbrev_np(3) instead.
This commit is contained in:
Todd C. Miller
2020-08-25 16:48:13 -06:00
parent 3235687d96
commit 019f1f6b93
5 changed files with 100 additions and 71 deletions

View File

@@ -740,6 +740,9 @@
/* Define to 1 if you have the `sig2str' function. */
#undef HAVE_SIG2STR
/* Define to 1 if you have the `sigabbrev_np' function. */
#undef HAVE_SIGABBREV_NP
/* Define to 1 if you use S/Key. */
#undef HAVE_SKEY

13
configure vendored
View File

@@ -23687,6 +23687,18 @@ done
if test x"${ac_cv_func_sig2str}${ac_cv_func_str2sig}" != x"yesyes"; then
for ac_func in sigabbrev_np
do :
ac_fn_c_check_func "$LINENO" "sigabbrev_np" "ac_cv_func_sigabbrev_np"
if test "x$ac_cv_func_sigabbrev_np" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_SIGABBREV_NP 1
_ACEOF
fi
done
if test x"${ac_cv_func_sigabbrev_np}" != x"yes"; then
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }strsig_test"
HAVE_SIGNAME="false"
ac_fn_c_check_decl "$LINENO" "sys_signame" "ac_cv_have_decl_sys_signame" "
@@ -23791,6 +23803,7 @@ esac
fi
fi
fi
fi
OLIBS="$LIBS"
LIBS="$LIBS $lt_cv_dlopen_libs"

View File

@@ -3498,6 +3498,8 @@ dnl Check for sys_signame or sys_sigabbrev if missing sig2str() or str2sig().
dnl Also enable unit tests for sig2str() and str2sig().
dnl
if test x"${ac_cv_func_sig2str}${ac_cv_func_str2sig}" != x"yesyes"; then
AC_CHECK_FUNCS([sigabbrev_np])
if test x"${ac_cv_func_sigabbrev_np}" != x"yes"; then
COMPAT_TEST_PROGS="${COMPAT_TEST_PROGS}${COMPAT_TEST_PROGS+ }strsig_test"
HAVE_SIGNAME="false"
AC_CHECK_DECLS([sys_signame, _sys_signame, sys_sigabbrev], [
@@ -3524,6 +3526,7 @@ AC_INCLUDES_DEFAULT
fi
fi
fi
fi
dnl
dnl Check for dl_iterate_phdr, may require -ldl

View File

@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2012-2015, 2017-2019 Todd C. Miller <Todd.Miller@sudo.ws>
* Copyright (c) 2012-2015, 2017-2020 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -32,20 +32,24 @@
#include <unistd.h>
#include "sudo_compat.h"
#include "sudo_util.h"
#if !defined(HAVE_SIGABBREV_NP)
# if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1
# define sudo_sys_signame sys_signame
# define sigabbrev_np(_x) sys_signame[(_x)]
# elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1
# define sudo_sys_signame _sys_signame
#elif defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 1
# define sudo_sys_signame sys_sigabbrev
#else
# ifdef HAVE_SYS_SIGABBREV
# define sigabbrev_np(_x) _sys_signame[(_x)]
# elif defined(HAVE_SYS_SIGABBREV)
# define sigabbrev_np(_x) sys_sigabbrev[(_x)]
# if defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 0
/* sys_sigabbrev is not declared by glibc */
# define sudo_sys_signame sys_sigabbrev
extern const char *const sys_sigabbrev[NSIG];
# endif
# else
# define sigabbrev_np(_x) sudo_sys_signame[(_x)]
extern const char *const sudo_sys_signame[NSIG];
# endif
#endif /* !HAVE_SIGABBREV_NP */
/*
* Translate signal number to name.
@@ -77,8 +81,10 @@ sudo_sig2str(int signo, char *signame)
return 0;
}
#endif
if (signo > 0 && signo < NSIG && sudo_sys_signame[signo] != NULL) {
strlcpy(signame, sudo_sys_signame[signo], SIG2STR_MAX);
if (signo > 0 && signo < NSIG) {
const char *cp = sigabbrev_np(signo);
if (cp != NULL) {
strlcpy(signame, cp, SIG2STR_MAX);
/* Make sure we always return an upper case signame. */
if (islower((unsigned char)signame[0])) {
int i;
@@ -87,6 +93,7 @@ sudo_sig2str(int signo, char *signame)
}
return 0;
}
}
errno = EINVAL;
return -1;
}

View File

@@ -1,7 +1,7 @@
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2019 Todd C. Miller <Todd.Miller@sudo.ws>
* Copyright (c) 2019-2020 Todd C. Miller <Todd.Miller@sudo.ws>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -37,19 +37,22 @@
#include "sudo_compat.h"
#include "sudo_util.h"
#if !defined(HAVE_SIGABBREV_NP)
# if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1
# define sudo_sys_signame sys_signame
# define sigabbrev_np(_x) sys_signame[(_x)]
# elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1
# define sudo_sys_signame _sys_signame
#elif defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 1
# define sudo_sys_signame sys_sigabbrev
#else
# ifdef HAVE_SYS_SIGABBREV
# define sigabbrev_np(_x) _sys_signame[(_x)]
# elif defined(HAVE_SYS_SIGABBREV)
# define sigabbrev_np(_x) sys_sigabbrev[(_x)]
# if defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 0
/* sys_sigabbrev is not declared by glibc */
# define sudo_sys_signame sys_sigabbrev
extern const char *const sys_sigabbrev[NSIG];
# endif
# else
# define sigabbrev_np(_x) sudo_sys_signame[(_x)]
extern const char *const sudo_sys_signame[NSIG];
# endif
#endif /* !HAVE_SIGABBREV_NP */
/*
* Many systems use aliases for source backward compatibility.
@@ -154,11 +157,11 @@ sudo_str2sig(const char *signame, int *result)
}
}
/* Check sys_signame[]. */
for (signo = 1; signo < NSIG; signo++) {
if (sudo_sys_signame[signo] != NULL) {
const char *cp = sigabbrev_np(signo);
if (cp != NULL) {
/* On macOS sys_signame[] may contain lower-case names. */
if (strcasecmp(signame, sudo_sys_signame[signo]) == 0) {
if (strcasecmp(signame, cp) == 0) {
*result = signo;
return 0;
}