Package: unixcw Severity: important Version: 2.3-3 Tags: patch
Hi, the current version fails to build on GNU/kFreeBSD. It incorrectly assumes that number of signals is given by macro SIGRTMAX. Moreover there is "off by one" bug even on Linux, as signal numbers starts with 1, see also /usr/include/bits/signum.h.Current code reject perfectly valid signal 64 in cw_register_signal_handler() and cw_unregister_signal_handler()
with EINVAL. Please find attached patch to fix all of that. There may be still problem with cw_register_signal_handler() and cw_unregister_signal_handler() for signal number 0. IMHO, it should be rejected directly with EINVAL. It would also be nice if you can inform upstream about this issues. Thanks in advance Petr
--- unixcw-2.3.orig/src/cwlib/cwlib.c +++ unixcw-2.3/src/cwlib/cwlib.c @@ -3008,7 +3008,18 @@ * initialized dynamically to SIG_DFL (if SIG_DFL is not NULL, which it * seems that it is in most cases). */ -static void (*cw_signal_callbacks[RTSIG_MAX]) (int); + +#if defined(NSIG) +#define SIG_MAX (NSIG) +#elif defined(_NSIG) +#define SIG_MAX (_NSIG) +#elif defined(RTSIG_MAX) +#define SIG_MAX ((RTSIG_MAX)+1) +#else +#error unknown number of signals +#endif + +static void (*cw_signal_callbacks[SIG_MAX]) (int); /** @@ -3194,14 +3205,14 @@ { int index; - for (index = 0; index < RTSIG_MAX; index++) + for (index = 0; index < SIG_MAX; index++) cw_signal_callbacks[index] = SIG_DFL; is_initialized = TRUE; } /* Reject invalid signal numbers, and SIGALRM, which we use internally. */ - if (signal_number < 0 || signal_number >= RTSIG_MAX + if (signal_number < 0 || signal_number >= SIG_MAX || signal_number == SIGALRM) { errno = EINVAL; @@ -3256,7 +3267,7 @@ int status; /* As above, reject unacceptable signal numbers. */ - if (signal_number < 0 || signal_number >= RTSIG_MAX + if (signal_number < 0 || signal_number >= SIG_MAX || signal_number == SIGALRM) { errno = EINVAL;