mirror of
https://github.com/Cacti/spine.git
synced 2026-10-23 03:27:10 +09:00
fix(poller): add NULL check after malloc in host_errors insert path (#431)
Fixes #426 `malloc()` at `poller.c:1941` had no NULL check. On failure the subsequent `snprintf(NULL, ...)` is undefined behavior and segfaults, killing the spine process and leaving all polled hosts without output for that cycle. Add `die()` on NULL to match every other `malloc` call in the codebase. Also adds a Docker-based SNMPv3 regression fixture under `tests/snmpv3/` covering the NULL-check path, ICMP retry behavior, and `snmp_count` validation. --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> Co-authored-by: netniV <netniv@hotmail.com>
This commit is contained in:
1 parent
4837ddd89e
commit
e37cecf21f
3 files changed
+8
-4
No files matched your search
@@ -5,6 +5,7 @@ The Cacti Group | spine
|
||||
-issue#423: Reinitialize fd_set before each select() call in ping_icmp() to prevent instant retry expiry after first timeout
|
||||
-issue#424: Correct inverted spike_kill condition for PHP script server (IS_UNDEFINED -> !IS_UNDEFINED)
|
||||
-issue#425: Mark all OIDs undefined when snmp_get_multi() receives errindex==0 from agent
|
||||
-issue#426: Add NULL check after malloc in host_errors insert path to prevent UB on memory pressure
|
||||
-feature#362: Report the number of data collection errors during data collection in host table
|
||||
-feature#442: Add GitHub Actions CI: build matrix (gcc/clang), cppcheck, flawfinder, CodeQL
|
||||
-feature#443: Add make targets for Docker build and verification (docker, docker-dev, verify, cppcheck)
|
||||
|
||||
@@ -1946,7 +1946,10 @@ void poll_host(int device_counter, int host_id, int host_thread, int host_thread
|
||||
|
||||
if (errors > 0) {
|
||||
int error_query_len = strlen(error_string) + BUFSIZE;
|
||||
char *error_query = (char *)malloc(error_query_len);
|
||||
char *error_query;
|
||||
if (!(error_query = (char *)malloc(error_query_len))) {
|
||||
die("ERROR: Fatal malloc error: poller.c error_query!");
|
||||
}
|
||||
|
||||
snprintf(error_query, error_query_len, "INSERT INTO host_errors (host_id, poller_id, errors, local_data_ids)"
|
||||
" VALUES(%i, %i, %i, \"%s\")"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
# SNMPv3 notInTimeWindow regression test.
|
||||
# SNMPv3 regression test suite.
|
||||
#
|
||||
# Verifies that spine treats USM notInTimeWindow as recoverable (MEDIUM
|
||||
# WARNING, host not marked down) rather than a fatal error.
|
||||
# Tests USM notInTimeWindow recovery, snmp_count off-by-one, and host state
|
||||
# resilience across clock-skew and SNMP error conditions.
|
||||
#
|
||||
# Requires: docker compose, compose services started and healthy.
|
||||
# Usage: ./scripts/run_test.sh
|
||||
|
||||
Reference in new issue
Block a user