mirror of
https://github.com/Cacti/spine.git
synced 2026-12-02 21:37:07 +09:00
## Summary The 1.2.x-affected subset of a batch of small, independent, unaddressed bugs from the open-issue backlog (the two develop-only issues from the same audit, #583 and #580, are not applicable here — see the companion PR for `develop`). ## Fixes - **`poll_host()` skips `mysql_thread_end()` when the device row is missing** — the early `return` on `num_rows != 1` released both DB connections and freed six allocations, but never called `mysql_thread_end()`, unlike the other two exit paths. Added the missing call. - **SNMPv3 passphrase scrubbing flag never set** — `zero_sensitive` was a function-local initialized to 0 and never assigned, so every guarded `memset()` was dead code. Made scrubbing of this module's own heap copies (`Apsz`/`Xpsz`) unconditional. Left the caller's `snmp_password`/`snmp_priv_passphrase` alone rather than also scrubbing those in place — those are `host_t`-owned and get reused for later session rebuilds against the same host, so zeroing them would have broken subsequent polls. - **`php_readpipe()` FD_SET without an FD_SETSIZE check** — `FD_SET()` doesn't range-check, so a read descriptor at or above `FD_SETSIZE` (1024 on glibc) wrote past the end of the on-stack `fd_set`. Added a bounds check that treats an out-of-range descriptor as a script-server failure (mark undefined, close, restart) instead of calling `FD_SET`/`select()` on it. - **Signal handler never re-arms, so the second SIGPIPE kills the poller** — every fatal signal reset itself to `SIG_DFL` and never re-armed. That's the right idiom for a real fault (SIGSEGV and friends re-execute and die with a core), but SIGPIPE is a routine, recurring condition — a second one previously killed the whole poller. Re-arm only SIGPIPE. - **spine fails to link on Fedora: undefined reference to `usmDESPrivProtocol`** — some distributions ship a `net-snmp-config.h` that advertises DES as the default privacy protocol while the shipped `libnetsnmp` doesn't export the symbol. Added an `AC_LINK_IFELSE` probe for the actual symbol and guarded the fallback to use `usmAESPrivProtocol` when it's absent. ## Testing Full build via WSL (`./bootstrap && ./configure --enable-warnings && make`) produces the `spine` binary with no new warnings in `poller.c`, `snmp.c`, `php.c`, or `error.c`. Confirmed the new `usmDESPrivProtocol` configure probe correctly detects the missing symbol in this build environment (which also lacks it) and takes the AES fallback path without a link error. Closes #594 Closes #600 Closes #605 Closes #607 Closes #575
191 lines
6.5 KiB
C
191 lines
6.5 KiB
C
/*
|
|
ex: set tabstop=4 shiftwidth=4 autoindent:
|
|
+-------------------------------------------------------------------------+
|
|
| Copyright (C) 2004-2024 The Cacti Group |
|
|
| |
|
|
| This program is free software; you can redistribute it and/or |
|
|
| modify it under the terms of the GNU Lesser General Public |
|
|
| License as published by the Free Software Foundation; either |
|
|
| version 2.1 of the License, or (at your option) any later version. |
|
|
| |
|
|
| This program is distributed in the hope that it will be useful, |
|
|
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
| GNU Lesser General Public License for more details. |
|
|
| |
|
|
| You should have received a copy of the GNU Lesser General Public |
|
|
| License along with this library; if not, write to the Free Software |
|
|
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
|
| 02110-1301, USA |
|
|
| |
|
|
+-------------------------------------------------------------------------+
|
|
| spine: a backend data gatherer for cacti |
|
|
+-------------------------------------------------------------------------+
|
|
| This poller would not have been possible without: |
|
|
| - Larry Adams (current development and enhancements) |
|
|
| - Rivo Nurges (rrd support, mysql poller cache, misc functions) |
|
|
| - RTG (core poller code, pthreads, snmp, autoconf examples) |
|
|
| - Brady Alleman/Doug Warner (threading ideas, implimentation details) |
|
|
+-------------------------------------------------------------------------+
|
|
| - Cacti - http://www.cacti.net/ |
|
|
+-------------------------------------------------------------------------+
|
|
*/
|
|
|
|
/* These functions handle simple singal handling functions for Spine. It was
|
|
written to handle specifically issues with the Solaris threading model in
|
|
version 2.8.
|
|
*/
|
|
|
|
#include "common.h"
|
|
#include "spine.h"
|
|
|
|
/*! \fn static void spine_signal_handler(int spine_signal)
|
|
* \brief interupts the os default signal handler as appropriate.
|
|
*
|
|
*/
|
|
static void spine_signal_handler(int spine_signal) {
|
|
/* A real fault (SIGSEGV/SIGBUS/...) resets to SIG_DFL and returns so the
|
|
* faulting instruction re-executes and dies with a core. SIGPIPE is a
|
|
* routine, recurring condition instead, and signal dispositions are
|
|
* process-wide: dropping it to SIG_DFL here, even briefly, would let a
|
|
* broken-pipe write on any other thread terminate the process during
|
|
* that window. Leave this handler permanently installed for SIGPIPE. */
|
|
if (spine_signal != SIGPIPE) {
|
|
signal(spine_signal, SIG_DFL);
|
|
}
|
|
|
|
set.exit_code = spine_signal;
|
|
|
|
/* variables for time display */
|
|
time_t nowbin;
|
|
struct tm now_time;
|
|
struct tm *now_ptr;
|
|
|
|
/* get time for poller_output table */
|
|
nowbin = time(&nowbin);
|
|
|
|
localtime_r(&nowbin,&now_time);
|
|
now_ptr = &now_time;
|
|
|
|
char *log_fmt = get_date_format();
|
|
char logtime[50];
|
|
|
|
strftime(logtime, 50, log_fmt, now_ptr);
|
|
|
|
switch (spine_signal) {
|
|
case SIGABRT:
|
|
fprintf(stderr, "%s FATAL: Spine Interrupted by Abort Signal\n", logtime);
|
|
break;
|
|
case SIGINT:
|
|
fprintf(stderr, "%s FATAL: Spine Interrupted by Console Operator\n", logtime);
|
|
break;
|
|
case SIGSEGV:
|
|
fprintf(stderr, "%s FATAL: Spine Encountered a Segmentation Fault\n", logtime);
|
|
exit(1);
|
|
break;
|
|
case SIGBUS:
|
|
fprintf(stderr, "%s FATAL: Spine Encountered a Bus Error\n", logtime);
|
|
break;
|
|
case SIGFPE:
|
|
fprintf(stderr, "%s FATAL: Spine Encountered a Floating Point Exception\n", logtime);
|
|
break;
|
|
case SIGQUIT:
|
|
fprintf(stderr, "%s FATAL: Spine Encountered a Keyboard Quit Command\n", logtime);
|
|
break;
|
|
case SIGPIPE:
|
|
fprintf(stderr, "%s FATAL: Spine Encountered a Broken Pipe\n", logtime);
|
|
break;
|
|
default:
|
|
fprintf(stderr, "%s FATAL: Spine Encountered An Unhandled Exception Signal Number: '%d'\n", logtime, spine_signal);
|
|
break;
|
|
}
|
|
}
|
|
|
|
static int spine_fatal_signals[] = {
|
|
SIGINT,
|
|
SIGPIPE,
|
|
SIGSEGV,
|
|
SIGBUS,
|
|
SIGFPE,
|
|
SIGQUIT,
|
|
SIGSYS,
|
|
SIGABRT,
|
|
0
|
|
};
|
|
|
|
static struct sigaction previous_sigchld;
|
|
static int previous_sigchld_saved = FALSE;
|
|
|
|
/*! \fn void install_spine_signal_handler(void)
|
|
* \brief installs the spine signal handler to stop certain calls from
|
|
* abending Spine.
|
|
*
|
|
*/
|
|
void install_spine_signal_handler(void) {
|
|
/* Set a handler for any fatal signal not already handled */
|
|
int i;
|
|
struct sigaction sa;
|
|
void (*ohandler)(int);
|
|
|
|
/* Child lifecycle code retains PIDs until waitpid() reaps them. Normalize
|
|
* an inherited SIG_IGN disposition so children remain zombies and their
|
|
* PIDs cannot be recycled before Spine observes their exit. */
|
|
if (sigaction(SIGCHLD, NULL, &previous_sigchld) == 0) {
|
|
previous_sigchld_saved = TRUE;
|
|
}
|
|
sa.sa_handler = SIG_DFL;
|
|
sigemptyset(&sa.sa_mask);
|
|
sa.sa_flags = 0;
|
|
sigaction(SIGCHLD, &sa, NULL);
|
|
|
|
for (i=0; spine_fatal_signals[i]; ++i) {
|
|
sigaction(spine_fatal_signals[i], NULL, &sa);
|
|
if (sa.sa_handler == SIG_DFL) {
|
|
sa.sa_handler = spine_signal_handler;
|
|
sigemptyset(&sa.sa_mask);
|
|
sa.sa_flags = SA_RESTART;
|
|
sigaction(spine_fatal_signals[i], &sa, NULL);
|
|
}
|
|
}
|
|
|
|
for (i=0; spine_fatal_signals[i]; ++i) {
|
|
ohandler = signal(spine_fatal_signals[i], spine_signal_handler);
|
|
if (ohandler != SIG_DFL) {
|
|
signal(spine_fatal_signals[i], ohandler);
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
/*! \fn void uninstall_spine_signal_handler(void)
|
|
* \brief uninstalls the spine signal handler.
|
|
*
|
|
*/
|
|
void uninstall_spine_signal_handler(void) {
|
|
/* Remove a handler for any fatal signal handled */
|
|
int i;
|
|
struct sigaction sa;
|
|
void (*ohandler)(int);
|
|
|
|
if (previous_sigchld_saved) {
|
|
sigaction(SIGCHLD, &previous_sigchld, NULL);
|
|
previous_sigchld_saved = FALSE;
|
|
}
|
|
|
|
for (i=0; spine_fatal_signals[i]; ++i) {
|
|
sigaction(spine_fatal_signals[i], NULL, &sa);
|
|
if (sa.sa_handler == spine_signal_handler) {
|
|
sa.sa_handler = SIG_DFL;
|
|
sigaction(spine_fatal_signals[i], &sa, NULL);
|
|
}
|
|
}
|
|
|
|
for ( i=0; spine_fatal_signals[i]; ++i ) {
|
|
ohandler = signal(spine_fatal_signals[i], SIG_DFL);
|
|
if (ohandler != spine_signal_handler) {
|
|
signal(spine_fatal_signals[i], ohandler);
|
|
}
|
|
}
|
|
}
|