34 Commits
Author SHA1 Message Date
TheWitness 0147745082 Fix a batch of unaddressed bugs (#594, #600, #605, #607, #575) (#628)
## 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
2026-09-22 09:42:34 -04:00
Thomas VincentandTheWitness 4e1ded7e25 fix: memory-safety and polling correctness backports for 1.2.x (#574)
Backports the memory-safety, process-lifecycle, and polling-correctness
fixes identified in the 1.2.x review.

Memory safety and resource handling:
- fix the `strncopy` one-byte overflow and keep its scan portable to
older Solaris
- reserve the `php_readpipe` terminator byte, enforce one aggregate
response/startup deadline, and recycle a server whose partial or
oversized response leaves unread protocol data
- keep log newline appends inside `flogmessage` and initialize the
buffer before `strftime`
- free settings-query results on missing rows and check allocation
results before dereference
- preserve allocation ownership when trimming recache command output

Process and privilege lifecycle:
- send quit to every PHP server before a shared grace period, then
signal/reap in parallel rounds with bounded SIGTERM-to-SIGKILL
escalation
- normalize `SIGCHLD` to `SIG_DFL`, verify retained children with
`waitpid` before signaling, and prevent active slots from overwriting
unreaped PIDs
- bound failed-server restart churn and make every no-server caller
return `U`
- block SIGPIPE only around complete script-server writes and consume
only a newly generated pending signal
- create pipe/socket descriptors close-on-exec, using
`pipe2`/`SOCK_CLOEXEC` when available and a serialized fallback
otherwise
- serialize `vfork`, optional libc `popen`, and the complete
process-wide euid-0 raw-socket window so data-input children cannot
inherit root
- remove unnecessary privilege elevation when closing raw sockets and
fail closed if privileges cannot be dropped

Polling correctness:
- preserve complete database hostnames, including bare IPv6 literals.
The removed host:port parser was dead: callers do not consume its
method/port outputs and overwrite those fields from the database, while
tokenizing the hostname truncated valid IPv6 input.
- validate IPv4 and ICMP header lengths before access, consume rejected
peeked datagrams, and correlate echo replies by host, type, identifier,
and sequence
- make `snmp_count` stop on internal Net-SNMP errors, distinguish SNMPv1
`noSuchName` walk completion, and avoid turning internal errors into
valid zero counts
- fail closed when device/item-count rows cannot be fetched, preventing
zero counts from becoming unbounded duplicate polls
- make CLI fatal paths return failure and guard nullable database row
fields

Verification:
- `./bootstrap` completes (using Homebrew `glibtoolize`; the initial
unavailable GNU `libtoolize` probe is non-fatal)
- default configure/build succeeds against Homebrew mysql-client,
net-snmp, and OpenSSL 3
- `--enable-popen` configure/build also succeeds
- both builds use `--enable-warnings` and `make -j4`; remaining warnings
are pre-existing macOS deprecations and unrelated unused variables
- `git diff --check` passes
- the blocking pre-push review gate passes all stages (critical/high,
secondary scanners, medium, and missing-test review)

Scope notes:
- The new close-on-exec handling covers descriptors created by the
changed PHP/script/ICMP paths. Existing MySQL, log, and Net-SNMP
descriptors do not yet have comprehensive close-on-exec coverage; that
broader descriptor audit should be a separate change rather than implied
by this backport.
- In the non-default `--enable-popen` mode, the existing timeout path
intentionally skips `pclose` and can retain a child until it exits. This
PR secures that mode's fork against the euid window but does not
redesign its legacy timeout ownership.
- Spine has no in-tree C test harness. The failure-mode paths were
statically reviewed and both supported build variants were compiled, but
deployment validation should still exercise PHP restart/orphan handling,
partial-response timeouts, SNMPv1 count behavior, and malformed/foreign
ICMP replies.

Closes #564
Closes #565
Closes #566
Closes #573
Closes #601
Closes #604
Closes #606
Closes #608

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Co-authored-by: TheWitness <thewitness@cacti.net>
2026-09-22 09:07:45 -04:00
TheWitness 17f92179a4 Fix: #365 - Removing Backtrace Support 2025-06-28 07:43:58 -04:00
TheWitness 113bf16328 QA: Prepare for Release and Update Copyrights 2024-08-07 08:44:32 -04:00
TheWitness 564d0ef6ff QA: Fix a few unused variables 2023-12-08 17:12:45 -05:00
Mark Brugnoli-Vinten 4d5c5dcd68 Update copyright year for 2023 2023-01-04 10:24:52 +00:00
TheWitness 793734843c Fixing #273 - Log time and #274 - Reduce SIGABORT's 2022-07-05 09:34:21 -04:00
TheWitness 287973f96c Output to standard error for segfault 2021-04-14 20:46:09 -04:00
TheWitness 757914793e Another fix for issue #197
On my gravestone, I want a quote something to the affect of "Here lies a man who hated the C, but loved the world around it".  Great language, fast, but too many rules for this old critter.

There are really four fixes here.

- This first is that the db_escape() function was basically not even working breaking the whole '--mibs' thing.
- When limiting the host list, you should not send everything on the poller back to the main server, only what was polled.  Minor, but a finer point.
- The signal handler needs to not mix it up by calling die().  Just fprintf() to standard error, backtrace if you segfaulted and go away.  I've found in a few cases that the spine will be left running, and when straced, it's blocked on I/O from trying to do too much while trying to 'die'.
- Lastly, when pushing log data to standard output for debugging, don't trim output
2021-03-13 10:43:10 -05:00
TheWitness ee2f552f97 Fixing Issue #189
[SPINE] latest 1.2.x branch - FATAL: Spine Encountered a Segmentation Fault
2021-02-16 22:15:20 -05:00
TheWitness c2be24949e Fix build problem on Cygwin 2021-01-03 09:41:54 -05:00
TheWitness 95c7350679 Updating copyright, preparing for release 2021-01-01 20:31:36 -05:00
TheWitness 4eb2b7f190 Add backtrace printing
Add backtrace output to stderr for signals
2020-11-27 10:57:24 -05:00
TheWitness bdfc997b8a Prep for 1.2.11 Release 2020-03-29 12:06:30 -04:00
cigamit 8fc523829a Update configure.ac for 1.2.3 release
Additionally update copright years.
2019-03-29 18:24:34 -05:00
netniV ef07a4ddd0 Resolving issue #70 2018-09-03 14:30:04 +01:00
netniV 905524f331 Resolving issue #67 2018-08-22 23:34:58 +00:00
Tony Roman 02c5a4615f Update copyright to 2018 2018-01-06 09:15:06 -05:00
Tony Roman eaa981b70e Update copyright to current year 2017-01-01 14:25:45 -05:00
cigamit 48eddd1e9c retry handled as best as it can be 2016-06-19 07:57:02 -05:00
cigamit 99d6d5270f deal with EINTR better 2016-06-18 16:06:19 -05:00
Tony Roman 9ea2b5d348 Update copyright 2015-06-08 14:16:52 -04:00
Tony Roman a1e4e4b8fc Update copyright date to 2014
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.8@7495 860744bd-22fc-0310-8c96-e9fe5004b5ca
2014-11-12 02:38:23 +00:00
Tony Roman 168474be8c - Update spine copyright
- Fix up documenation


git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.8@7398 860744bd-22fc-0310-8c96-e9fe5004b5ca
2013-08-04 20:32:56 +00:00
Tony Roman 7128b774e5 Update spine copyrights to 2012
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@7020 860744bd-22fc-0310-8c96-e9fe5004b5ca
2012-02-27 07:18:50 +00:00
Tony Roman f76a465dcf Update spine copyright dates
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@6235 860744bd-22fc-0310-8c96-e9fe5004b5ca
2011-01-27 03:54:19 +00:00
Larry Adams 32bbae5007 QA: More copyright years.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@6000 860744bd-22fc-0310-8c96-e9fe5004b5ca
2010-06-12 19:34:44 +00:00
Larry Adams 55cb955d2e QA: Update copyrights
QA: Oops removing snmp_init broke snmpv3
Feature: don't complain on wrong snmp types, just roll with it

git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4551 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-03-06 02:44:08 +00:00
Larry Adams b099e3d543 Initial rename, Add tabs stops and autoindent, fix copyright
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/main@4142 860744bd-22fc-0310-8c96-e9fe5004b5ca
2007-09-10 12:28:22 +00:00
Larry Adams cdeb86901c -bug#0000879/0000872: cactid doesn't always report error messages before dying
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3840 860744bd-22fc-0310-8c96-e9fe5004b5ca
2006-12-31 18:30:07 +00:00
Larry Adams 43e4ee3173 Correct in-line coding issues with some OS'.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3782 860744bd-22fc-0310-8c96-e9fe5004b5ca
2006-09-23 01:23:17 +00:00
Larry Adams 494d0afe83 Various fixes around Solaris
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3698 860744bd-22fc-0310-8c96-e9fe5004b5ca
2006-08-09 20:51:45 +00:00
Larry Adams 2474c0aacf -bug: Don't perform a reindex a check for a data query if you already have to reindex
-bug#0000745: cactid: search path for mysql and snmp does not include /usr/pkg
-bug#0000748: cactid doesn't handle special charectors
-bug#0000749: Cactid 0.8.6g won't accept special characters from data template
-bug#0000750: poller doesn't check for snmp if udp ping fails
-bug#0000752: Problem with OID truncation with cactid


git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3648 860744bd-22fc-0310-8c96-e9fe5004b5ca
2006-07-14 04:27:28 +00:00
Larry Adams 1dd0502666 -bug#0000724: cactid truncate script command when reindex
-bug#0000736: Solaris 8 : Alarm Clock message 
-feature: enabled signal handling in cactid
plus significant header rearrangement and correction of some compile issue.

git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3613 860744bd-22fc-0310-8c96-e9fe5004b5ca
2006-04-30 21:30:51 +00:00