25 Commits
Author SHA1 Message Date
Thomas Vincent e8a4b9aac9 fix: poller correctness bugs, with fuzz and integration coverage (#542)
Poller correctness and memory-safety fixes, with the ICMP hardening from
#543 folded in.

Verified in a clean `ubuntu:24.04` container: builds at **38 warnings**
against develop's 39, and the unit tests build and pass on Linux (39
assertions across three binaries).

**Fixes**
- `php_readpipe` off-by-one — the old bound let `bptr` reach
`result_string + 2048` and then wrote the terminator one byte past a
2048-byte allocation.
- `get_namebyhost` used `strtok`, which keeps one process-wide save
pointer, and runs unlocked on every poller thread. Two devices could be
polled at each other's addresses. Now `strtok_r`.
- The log date format was read from `default_dateformat`; Cacti's key is
`default_date_format`, so the lookup never matched and the format was
never loaded.
- `db_query` returns `mysql_store_result()` directly, which is NULL on
store failure. The NULL check ran *after* `mysql_fetch_row`, so the
crash happened one line before the guard.
- `snmp_count` logged a Net-SNMP `errstat` without setting either loop
flag, rebuilding the identical GETNEXT forever and pinning a thread
until the poll interval ended.
- `php_close` skipped the `close()` when the quit write failed with
EPIPE, leaking a descriptor per script-server restart.
- The reap loop's delay was compiled out on `SOLAR_THREAD` builds, so
both phases burned twenty `WNOHANG` polls in nanoseconds and the child
was never reaped.
- ICMP replies are validated for length and matched on id/sequence; on
Cygwin the peeked datagram is now drained, which previously busy-spun
until host timeout.
- The fatal signal handler no longer calls
`malloc`/`localtime_r`/`fprintf` before `_exit` — on a SIGSEGV caused by
heap corruption that deadlocked on the allocator's lock instead of
dying.
- The unit test Makefile was hardcoded to `/opt/homebrew` paths and
`-std=gnu23`, so it could not build on Linux at all. Now pkg-config
driven.

Supersedes #543.

**Added since the first revision**
- `snmp_get_multi()` now checks the varbind type before formatting.
Under v2c an agent reports a per-OID failure as an inline exception
varbind while the PDU `errstat` stays `NOERROR`, so `snprint_value()`
rendered the exception as literal text and stored it as a value.
- Two warning sources removed: a dangling line continuation ending
`sql.h`, and `strncopy()` now using `memcpy` where the byte count is
already exact. Warnings drop from **39 to 7**.

Closes #551
Closes #232
- `read_config_options()` issued 23 separate `SELECT ... FROM settings
WHERE name = ?` round trips at startup; they are now one bulk read
served from memory. Call sites are unchanged.

Closes #330

**Test infrastructure**
- The SNMPv3 integration fixture was broken: the image shipped a binary
that could not start (`libmysqlclient.so.21: cannot open shared object
file`). The build context carried `*.o`, `spine`, `Makefile` and
`config.status`, so `make` treated them as current, skipped compiling,
and packaged a binary linked against libraries the runtime image does
not have. `.dockerignore` now excludes build output. The fixture runs
end to end: spine polls the SNMPv3 device, reads `uptime`, writes to
`poller_output` and exits 0.
- Two libFuzzer targets, run per PR and weekly: the host string parser
and the ICMP reply parser. The second drives
`spine_icmp_classify_reply()`, extracted from `ping_icmp` so the bounds
walk over a shared raw socket is reachable by a test. 15M executions
under ASan/UBSan, no crashes.


**Added in this revision**
- `output_regex` was applied only in the in-loop OID drain, not the pass
after the loop that handles whatever did not fill a `MAX_OIDS` batch, so
a device whose OID count missed a boundary stored raw values. A single
data source is always the leftover case.
`tests/integration/test_output_regex.sh` now asserts on the value: it
fails on the parent commit with the raw reading and passes here with the
filtered one. Addresses #210; the feature stays dormant until Cacti
populates `poller_item.output_regex`.

Merge before #555, which needs the `get_namebyhost` fix above to resolve
a device hostname at all.

---------

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
2026-08-31 10:03:55 +01:00
TheWitness ef783a0ff4 Copyrights (#396) 2026-02-15 22:39:58 -05:00
TheWitness 8ffdcf01aa Fix: #365 - Removing Backtrace support 2025-06-26 23:23:51 -04:00
Linegod 169210b03c typos 2025-02-10 22:22:21 -06:00
TheWitness cea199ec6c Update all copyrights 2024-10-30 18:28:27 -04:00
Mark Brugnoli-Vinten b3303d3e16 Update copyright year for 2023 2023-01-04 10:21:05 +00:00
TheWitness c1816b3241 Fixing Issue #243
FreeBSD13 compilation fail
2022-03-29 07:38:04 -04:00
TheWitness 16c0b2b0d5 Fixing Issues #192 and #193
- Spine does not properly use the mysql reconnect option
- Spine segfaults when performing certain re-index operation
- This change also corrects some compiler warnings.
2021-02-22 07:59:10 -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
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
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 6fd830061c -bug: Increase the number of file descriptors in Cygwin to 512, 64 does not work for large systems.
-bug: Restore meaningful notices when running from command line
-bug: Allow the use of snmpgetnext instead of snmpget for snmp_ping.  This should be very reliable.


git-svn-id: svn+ssh://repo.cacti.net/var/data/svnroot/cacti/branches/BRANCH_0_8_6/cactid@3844 860744bd-22fc-0310-8c96-e9fe5004b5ca
2006-12-31 21:43:03 +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