ConfigManager: null-terminate config buffer before parsing - #25
Open
jamesmulcahy wants to merge 1 commit into
Open
jamesmulcahy wants to merge 1 commit into
jamesmulcahy wants to merge 1 commit into
Conversation
load_config allocated exactly file_size bytes, read the file into it and passed it to cJSON_Parse, which expects a null-terminated string. The parser could read past the end of the allocation, so trailing heap bytes could make a valid config fail to parse (or be misread). The fread result was also ignored, and ftell returning -1 was treated as a valid size. Allocate one extra byte and terminate the buffer, reject non-positive sizes, and fail if fewer bytes were read than expected. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X7aYyRjzk53Sd7gxF46E3u
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
ConfigManager::load_configallocates exactlyfile_sizebytes, readsconfig.jsoninto the buffer and passes it tocJSON_Parse.cJSON_Parseexpects a null-terminated string, so the parser can read past the end of the allocation: whatever heap bytes follow can make a valid config fail to parse, or in the worst case be misread. A config that fails to load puts the panel into AP mode with default settings.Two smaller issues on the same path:
freadresult is ignored, so a short read is parsed as if it were the whole file.ftellreturning-1passes thefile_size != 0check and is used as an allocation size.This PR:
file_size + 1bytes and null-terminates the buffer after reading.🤖 Generated with Claude Code
https://claude.ai/code/session_01X7aYyRjzk53Sd7gxF46E3u