Skip to content

fix: unchecked allocations, log newline overflow, and leaked result sets - #576

Closed
somethingwithproof wants to merge 3 commits into
Cacti:developfrom
somethingwithproof:fix/allocation-and-leak-guards
Closed

fix: unchecked allocations, log newline overflow, and leaked result sets#576
somethingwithproof wants to merge 3 commits into
Cacti:developfrom
somethingwithproof:fix/allocation-and-leak-guards

Conversation

@somethingwithproof

Copy link
Copy Markdown
Member

Three defects, one commit each.

Closes #564 — unchecked calloc() in spine.c. php_processes, debug_devices, db_pool_local and db_pool_remote are dereferenced on the statement after allocation. #542 gave the two in poller.c a die(); these were missed. All five calloc() calls in the file are now guarded.

Closes #565 — newline written past flogmessage. The two strncat() calls are bounded so the message can fill LOGSIZE exactly, after which strcat() put the newline at LOGSIZE-1 and its terminator at LOGSIZE. The newline is now appended only when a byte is free, and replaces the final character otherwise. Three cmocka cases cover it, with a canary after the buffer so an overflow is observable rather than merely undefined.

Closes #566MYSQL_RES leaked on the no-row branch. getsetting(), getpsetting(), getglobalvariable() and the Cacti version read each returned from the mysql_fetch_row() == NULL branch without freeing, while every other exit in those functions frees.

Verification. Clean ubuntu:24.04 container: builds at 4 warnings, matching develop exactly. make check passes all three binaries, make distcheck passes.

Not folded into #555. That PR is ping-specific and currently sits on a stale "merge conflicts" block that only needs lifting; adding unrelated spine.c and util.c changes would force a fresh review of work that is otherwise ready.

The 1.2.x half of these is going onto #574, since all three are present there too.

php_processes, debug_devices and both connection pools were dereferenced on
the next statement. Cacti#542 gave the poller.c allocations a die() on failure;
these were missed. Closes Cacti#564

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
getsetting(), getpsetting(), getglobalvariable() and the Cacti version read
each returned from the NULL-row branch without freeing, while every other
exit in those functions frees. Closes Cacti#566

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
The strncat() calls are bounded to fill the buffer exactly, after which
strcat() wrote the newline at LOGSIZE-1 and its terminator one past the end.
The newline is now only appended when a byte is free, and replaces the last
character otherwise. Closes Cacti#565

Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
@somethingwithproof

Copy link
Copy Markdown
Member Author

Superseded by #578, which carries the same spine.c allocation guards, a larger util.c change that also covers #567, and better coverage: five cases against the shipped spine_log() rather than the three here, which test a copy of append_newline() declared in the test file.

Closing to keep one review rather than two for the same fixes. #564, #565 and #566 are tracked on #578.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

1 participant