Fixed out-of-bounds read in module protocol when a '%' line has no '='#6178
Open
aizu-m wants to merge 1 commit into
Open
Fixed out-of-bounds read in module protocol when a '%' line has no '='#6178aizu-m wants to merge 1 commit into
aizu-m wants to merge 1 commit into
Conversation
AddressSanitizer, parsing a "%" module-protocol line with no "=":
ERROR: AddressSanitizer: SEGV on a READ
#0 strlen
cfengine#1 BufferNewFrom buffer.c:68
cfengine#2 ModuleProtocol evalfunction.c:10252
Came across this whilst reading the module protocol parser. The "%" case
builds the JSON payload with
BufferNewFrom(line + strlen(name) + 1 + 1,
length - strlen(name) - 1 - 1);
which assumes a well-formed "%name=<json>" line. But sscanf("%256[^=]=",
name) also returns with name set when the line carries no "=": it leaves
the whole tail in name. So strlen(name) == length - 1, the length argument
underflows to SIZE_MAX, and the data pointer steps one past the terminating
NUL. BufferAppend() then scans from there and walks off the heap line
buffer.
read_module_protocol() hands arbitrary file lines straight to
ModuleProtocol(), so a single line "%x" is enough to reproduce it.
The other directives ("=", "@", ...) already guard their input; the "%"
case did not. Only do the arithmetic once the "=" delimiter is present.
Changelog: Title
Signed-off-by: aizu-m <aizumusheer2@gmail.com>
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.
AddressSanitizer, parsing a "%" module-protocol line with no "=":
Came across this whilst reading the module protocol parser. The "%" case
builds the JSON payload with
which assumes a well-formed "%name=" line. But sscanf("%256[^=]=",
name) also returns with name set when the line carries no "=": it leaves
the whole tail in name. So strlen(name) == length - 1, the length argument
underflows to SIZE_MAX, and the data pointer steps one past the terminating
NUL. BufferAppend() then scans from there and walks off the heap line
buffer.
read_module_protocol() hands arbitrary file lines straight to
ModuleProtocol(), so a single line "%x" is enough to reproduce it.
The other directives ("=", "@", ...) already guard their input; the "%"
case did not. Only do the arithmetic once the "=" delimiter is present.