fix: NULL checks, switch fall-through, thread safety, buffer bounds#520
Closed
somethingwithproof wants to merge 2 commits intoCacti:developfrom
Closed
fix: NULL checks, switch fall-through, thread safety, buffer bounds#520somethingwithproof wants to merge 2 commits intoCacti:developfrom
somethingwithproof wants to merge 2 commits intoCacti:developfrom
Conversation
37a5f65 to
9aee4f4
Compare
…RITICAL) Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
9aee4f4 to
4f2f753
Compare
…HIGH) Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
4f2f753 to
205f522
Compare
Contributor
Author
|
Consolidated into mega PR #522 for independent mergeability. |
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.
Summary
Fixes all 10 HIGH-severity findings from static analysis / code review.
Findings Addressed
HIGH-1: Missing NULL check after calloc for poller_items (poller.c)
Added
die()guard aftercallocat the poller_items allocation.HIGH-2: Missing NULL check after calloc for snmp_oids (poller.c)
Added
die()guard aftercallocat the snmp_oids allocation.HIGH-3: Missing NULL check after malloc for error_string, buf_size, buf_errors (poller.c)
Added combined NULL check for all three
malloccalls before dereferencing.HIGH-4: Switch fall-through in get_date_format (util.c)
Added
break;after eachcasebody. Every case was falling through to the next, so only the default format was ever used.HIGH-5: db_get_connection NULL return not checked (poller.c)
Added NULL checks with
die()for both local and remote database connections.HIGH-6: db_escape output buffer overflow risk (sql.c)
Input is now always capped to
(trim_limit / 2) - 1before passing tomysql_real_escape_string, regardless of whether the escaped size exceedsmax_size.HIGH-7: db_column_exists column name unescaped (sql.c)
Added character validation loop: only alphanumeric and underscore characters are accepted. Invalid column names log an error and return FALSE.
HIGH-8: Thread-unsafe static seq in ping_icmp (ping.c)
Replaced mutex-protected
seq++with__sync_fetch_and_add(&seq, 1)(GCC atomic built-in). Variable declaredvolatilefor visibility.HIGH-9: Unbounded sprintf in poller_push_data_to_main (util.c)
Replaced all
sprintfcalls withsnprintfbounded by remaining space in theHUGE_BUFSIZEbuffer.HIGH-10: snprintf uses wrong buffer size constant (poller.c)
Changed
snprintf(poll_result, BUFSIZE, ...)tosnprintf(poll_result, RESULTS_BUFFER, ...)at both locations to match the actualmalloc(RESULTS_BUFFER)allocation fromsnmp_get.Verification
make clean && make-> 0 errors, 0 warningsTest plan