fix: allocation checks, a log buffer overflow, result leaks, and a per-line rebuild - #578
Closed
somethingwithproof wants to merge 6 commits into
Closed
Conversation
TheWitness
previously approved these changes
Sep 1, 2026
Member
|
Merge conflicts. |
php_processes, debug_devices and the two connection pools were dereferenced on the next line without testing the allocation. Closes Cacti#564 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The two strncat() calls above it may fill flogmessage exactly, so the unconditional strcat() put the terminator one byte past a LOGSIZE buffer. Closes Cacti#565 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Closes Cacti#566 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The format depends only on two settings read in read_config_options(), so rebuilding it per log line cost a malloc/free pair and two switches. Closes Cacti#567 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Adds a suite that includes util.c the way test_util_strings.c does, so the date format caching, the settings-helper result release and the bounded newline are exercised as shipped rather than as copies, plus an LD_PRELOAD allocation-failure test for the two startup guards no unit test can reach. test_linked freed the result of get_date_format() and expected that call to clamp; both moved to set_date_format() with this change, so its assertions move with them. Changed-line coverage on this branch goes from 38% to 79%; the remainder needs a live database and is noted in the pull request. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
somethingwithproof
force-pushed
the
fix/spine-alloc-and-log-hardening
branch
from
September 1, 2026 03:21
e717175 to
bbc98f1
Compare
This was referenced Sep 2, 2026
Member
Author
|
Conflicts are cleared. GitHub reports this |
This was referenced Sep 3, 2026
Member
Author
|
Consolidated into #597, which carries this branch's commits unchanged. Every pair of these ten conflicted on Nothing here is dropped. Reopen this if you would rather review it separately. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Four small fixes in
spine.candutil.c, all found while auditing classes that #542 and #557 fixed elsewhere in the tree but did not finish.Based on current develop, after #569 and #570.
#564 —
php_processes,debug_devices,db_pool_localanddb_pool_remotewere dereferenced on the line aftercalloc()without testing the result.#542gave the two inpoller.cadie(); these were missed. Same treatment, same message shape.snmp.c:1028andutil.c:124already checked theirs.#565 —
spine_log()bounds bothstrncat()calls so the message may fillflogmessageexactly, then appended the newline unconditionally, putting the terminator one byte past aLOGSIZEstack buffer. Same class as issue#561. The append is now bounded.#566 — four settings helpers returned without
db_free_result()when the query reported rows but the fetch yieldedNULL. Every other exit in each function frees it.#567 —
get_date_format()did amalloc/freepair, two range checks and two switches on every log line to rebuild a string that only depends on two settings read once at config load. It is now built inread_config_options(), while spine is still single threaded, andget_date_format()returns that storage.spine_log()no longer frees it. No behaviour change; the format for every code is unchanged, which the existing tests intest_safety_fixes.calready assert.Verification. Clean
ubuntu:24.04container: builds at 4 warnings, matching develop, andmake checkpasses all four suites. The new test is wired into thecheck_PROGRAMSlist #570 added.tests/unit/test_log_newline_bound.cis new and pins #565 down. It fails against the oldstrcat(): built with ASan and the pre-fix predicate,test_full_buffer_is_left_alonereports a stack-buffer-overflow; with the fix all five pass.Two things deliberately not here. All fourteen
mysql_fetch_row()call sites are already guarded, by the loop condition or an explicit test, so there was nothing to fix beyond the leak in #566. And the eightstrcat()calls atutil.c:885-914append compile-time literals intoBUFSIZEbuffers that were just zeroed, well under 100 bytes total; they are safe by construction and left alone.