-
Notifications
You must be signed in to change notification settings - Fork 634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix potential buffer overflow in parseStringValue #152
Conversation
CHECK_EQUAL_C_INT(SHADOW_JSON_ERROR, rc); | ||
|
||
/* Ensure there was no attempt to write to a buffer that's too small. */ | ||
for(i = 0; i < STRING_BUFFER_LENGTH; i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: You could do a mem compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't that require keeping an additional block of all-zero memory around?
|
||
CHECK_EQUAL_C_INT(3, r); | ||
CHECK_EQUAL_C_INT(SUCCESS, rc); | ||
CHECK_EQUAL_C_STRING("this is a longer string for test 2", parsedString); | ||
} | ||
|
||
/* Test that parsing a string doesn't overflow the given buffer. */ | ||
TEST_C(JsonUtils, ParseStringWithBufferTooSmall) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should test the happy path too :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like when the buffer is big enough? I think that's adequately tested by the integration tests (jobs integration test).
@@ -354,28 +354,28 @@ bool isJsonValidAndParse(const char *pJsonDocument, void *pJsonHandler, int32_t | |||
} | |||
|
|||
static IoT_Error_t UpdateValueIfNoObject(const char *pJsonString, jsonStruct_t *pDataStruct, jsmntok_t token) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A look up table could look better. Though it is a risky change.
@@ -170,12 +170,9 @@ IoT_Error_t parseBooleanValue(bool *b, const char *jsonString, jsmntok_t *token) | |||
IOT_WARN("Token was not a primitive."); | |||
return JSON_PARSE_ERROR; | |||
} | |||
if(jsonString[token->start] == 't' && jsonString[token->start + 1] == 'r' && jsonString[token->start + 2] == 'u' | |||
&& jsonString[token->start + 3] == 'e') { | |||
if(strncmp(jsonString + token->start, "true", 4) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Requires the inclusion of a buffer size in jsonStruct_t.
In response to #151.