Commit Graph
118 Commits
Author SHA1 Message Date
Thomas Vincent df528b0fd2 fix(runtime): [1.2.x] backport worker stacks SNMP locking and input boundaries (#662)
Backport the applicable runtime bugs from develop #644, #646 and #660.
Raise small platform worker stacks while preserving larger defaults and
rejecting overflowing buffer configurations. Serialize SNMP session
construction, cleanup and every SNMPv3 request process-wide while v1 and
v2c requests stay parallel. Net-SNMP's README.thread says SNMPv3 support
was never checked for multi-threading correctness. One unresponsive v3
agent now delays other v3 polls by up to timeout x (retries + 1);
narrowing the lock needs the asynchronous API and is a develop-only
follow-up. Reject unavailable PHP reader slots and invalid host/thread
CLI numbers before indexing or sizing state. Consume overlong config
lines once, parse final lines without a newline, and keep config values
out of warnings.

Merge after #661. This keeps the flat maintenance sources and existing
runtime interfaces; no new dependencies or CI gates. Release notes will
be collected in the final maintenance PR.

Validation: native build and version smoke test pass through mise.
ASan/UBSan contracts exercise worker-stack defaults and errors,
active-session SNMP locking, and physical config-line boundaries. A
probe linked to the maintenance production objects passes five
script-output boundaries and three unavailable PHP slot cases. Seven
invalid numeric CLI invocations fail before config/database access. The
critical flawfinder gate passes. No live database or device was
contacted.

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-10-22 16:34:34 -04:00
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 e4c62fd230 QA: Fix a few minor leaks in spine 2025-08-25 11:55:26 -04:00
TheWitness af323e479d QA: Fix to warnings from user testing 2025-06-30 09:50:28 -04:00
TheWitness 1d9793f22b Fix: Remove column check and no more compiler warnings 2025-06-28 08:35:55 -04:00
TheWitness 113bf16328 QA: Prepare for Release and Update Copyrights 2024-08-07 08:44:32 -04:00
TheWitness 99897ee6c6 Fixing Issue #298 - Timeout
Odd Cacti log format issue when script server timeout happened
2023-01-18 19:05:33 -05:00
Mark Brugnoli-Vinten 4d5c5dcd68 Update copyright year for 2023 2023-01-04 10:24:52 +00:00
TheWitness 3c18382eb0 QA on #292 & #293 - Missed minor change 2022-12-16 10:02:30 -05:00
TheWitness 961dab27fb Fixing #292 and #293 - SQL_NO_CACHE & Logging
* Improve Script Server Timeout Logging
* Add SQL_NO_CACHE to Spine Queries
2022-12-16 09:58:33 -05:00
TheWitness de24519b35 QA on #277
Had the wrong order on the version compare
2022-08-22 18:22:49 -04:00
TheWitness 7dbbce03ac Fixing #277 - Better handshake with script server
Spine should prevent the script server from connecting to remote when offline
2022-08-22 16:52:51 -04:00
TheWitness 715ae414c9 Fixing Issue #188
Allow more concurrent script servers.
2021-02-07 09:23:42 -05:00
TheWitness 95c7350679 Updating copyright, preparing for release 2021-01-01 20:31:36 -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
cigamit 172730c86b Fix all outstanding memory leaks in Spine 2018-08-11 09:13:49 -05: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 64af1da0f1 resolving bug#2196 2016-08-28 18:34:25 -05:00
cigamit aaad676ba3 resolving spine issues with semaphore EINTR being missed
not trapping on the active thread wait caused spine to exit early
intermittently.
2016-04-24 14:21:56 -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
Larry Adams 5fcef9f713 -bug: Script server results with special characters can cause segfaults
-feature: Add additional ping methods to allow more precise snmp pings
-bug#0001968: Spine Error with Cisco FWSM firewalls

git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@6759 860744bd-22fc-0310-8c96-e9fe5004b5ca
2011-09-09 19:06:27 +00:00
Larry Adams b7c3f10702 -bug#0001899: spine treats undef replies as 0
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@6253 860744bd-22fc-0310-8c96-e9fe5004b5ca
2011-01-28 23:44:48 +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
Reinhard Scheck 4a8707984b some typos
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@6232 860744bd-22fc-0310-8c96-e9fe5004b5ca
2011-01-20 21:56:32 +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 10a2988ddd QA: Minor debugging aids.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@5624 860744bd-22fc-0310-8c96-e9fe5004b5ca
2010-01-18 20:00:46 +00:00
Larry Adams c0edf61cac QA: Rework some file descriptor logic
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@5623 860744bd-22fc-0310-8c96-e9fe5004b5ca
2010-01-18 18:39:51 +00:00
Larry Adams 84e76ed3bf QA: Second close/open of Script Server was not required
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@5622 860744bd-22fc-0310-8c96-e9fe5004b5ca
2010-01-18 17:28:22 +00:00
Larry Adams e85bdae023 -bug: Invalid use of FDSETSIZE can cause issue with Script Server
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@5621 860744bd-22fc-0310-8c96-e9fe5004b5ca
2010-01-18 17:16:22 +00:00
Larry Adams 3ba064be9b QA: Softtabs issues
QA: One exception process test.

git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@5603 860744bd-22fc-0310-8c96-e9fe5004b5ca
2010-01-16 16:17:37 +00:00
Larry Adams 76dbc9379c -QA: Clean up several new line characters
-QA: Modify logging to help 'some' people understand

git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4994 860744bd-22fc-0310-8c96-e9fe5004b5ca
2009-04-10 21:06:52 +00:00
Larry Adams 99d707e24a -Info: eliminate one spurious warning and change type to ssize_t.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4992 860744bd-22fc-0310-8c96-e9fe5004b5ca
2009-04-10 00:26:14 +00:00
Larry Adams ab6cc067d5 Patches thanks to "Panagiotis H.M. Issaris" <panagiotis@gmail.com>
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4764 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-10-13 23:56:01 +00:00
Larry Adams 928fabf602 -feature: Allow overriding the default results buffer size
-feature: Allow overriding the default max mysql buffer (insert) size
-feature: Allow overriding the maximum simultaneous scripts setting


git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4704 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-09-07 21:15:33 +00:00
Larry Adams 1170833b71 -QA: tweak so as not too loose a single poll after the crash
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4618 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-06-23 22:02:41 +00:00
Larry Adams 2c1bfcd630 -bug: If the script server goes away due to a syntax problem, it will not restart
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/0.8.7@4617 860744bd-22fc-0310-8c96-e9fe5004b5ca
2008-06-23 21:52:05 +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 49b8a2cd62 More libtool compatibility
BUG: snmp not initialized under some circumstances
BUG: remove some Wall warnings

git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/spine/branches/main@4226 860744bd-22fc-0310-8c96-e9fe5004b5ca
2007-10-11 22:41:02 +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 903424d8b9 Segfaults gone forever...
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@4002 860744bd-22fc-0310-8c96-e9fe5004b5ca
2007-06-29 02:36:45 +00:00
Larry Adams cd02ee780c -feature: add Net-SNMP Library vs. Header check prior to execution
-feature: enabled signal handling in cactid


git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3973 860744bd-22fc-0310-8c96-e9fe5004b5ca
2007-06-20 02:29:53 +00:00
Larry Adams ad0c340370 Updates include some tweaks (beta) to multiple snmp agent hosts.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3920 860744bd-22fc-0310-8c96-e9fe5004b5ca
2007-04-28 03:03:10 +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 e44a1ca175 -bug: Cactid Script Server would not work with cgi version of php. Now it does.
git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3827 860744bd-22fc-0310-8c96-e9fe5004b5ca
2006-12-24 18:24:27 +00:00