You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, while fuzz testing FreeRTOS using Syzkaller, I encountered a KASAN heap-out-of-bounds error during testing, within the cJSON module.
I use cJSON_CreateObject()to get a json object, then add a string field, then generate JSON string. When I executing here, some wrongs occur.
This is my SPEC which can trigger the bug:
BUG: KASAN: heap-out-of-bounds in 0x400e1676
Read of size 1 at addr 0x3ffcadc8
Backtrace:
0x40081ecd:0x3ffc0e10
0x4008c685:0x3ffc0e30
0x400ee115:0x3ffc0e50
0x400e1673:0x3ffc0e70
0x400e20e0:0x3ffc0e90
0x400e1d09:0x3ffc0eb0
0x400e1dc0:0x3ffc0ed0
0x400e2cf7:0x3ffc0fa0
0x400e5711:0x3ffc0fc0
0x400e3511:0x3ffc0ff0
0x400e6b08:0x3ffc1040
0x400e6bd9:0x3ffc11f0
0x400e6da7:0x3ffc1210
0x40152aab:0x3ffc12d0
0x4008d35d:0x3ffc1300
It seems there is an illegal access at /path/to/cJSON.c in the print_string_ptr function. In line 935, and it is the loop's for (input_pointer = input; *input_pointer; input_pointer++) logical fault, you can see the ptr input_pointer will not stop until read the '\0', so if the string does not match the specification, which means it doesn't end with '\0', there will be problems with the loop. It will visit the illegal memory.
Not only that, but it is also possible that an invalid character was entered, and when the pointer moved to the invalid character, the loop could not process that character.
So the loop should add a check on the range of the string and an exception for invalid characters.
/* Render the cstring provided to an escaped version that can be printed. */staticcJSON_boolprint_string_ptr(constunsigned char*constinput, printbuffer*constoutput_buffer)
{
...
/* set "flag" to 1 if something needs to be escaped */for (input_pointer=input; *input_pointer; input_pointer++)
{
switch (*input_pointer)
{
case'\"':
case'\\':
case'\b':
case'\f':
case'\n':
case'\r':
case'\t':
/* one character escape sequence */escape_characters++;
break;
default:
if (*input_pointer<32)
{
/* UTF-16 escape sequence uXXXX */escape_characters+=5;
}
break;
}
}
output_length= (size_t)(input_pointer-input) +escape_characters;
...
}
Expected Behavior
The program should execute without any memory errors or crashes.
Actual Behavior
The program crashes with a KASAN report indicating a heap-out-of-bounds error.
Additional Information
It would be greatly appreciated if you could review this bug report. Any suggestions or feedback you can provide would be very helpful. Thank you for your time.
The text was updated successfully, but these errors were encountered:
I'm confused by the fuzz test. The input volatile long a0 is not used. The test only creates a json object and prints it, then it frees both. How does this fuzzer work?
Bug Report
Required Info:
Steps to reproduce issue:
Hi, while fuzz testing FreeRTOS using Syzkaller, I encountered a KASAN heap-out-of-bounds error during testing, within the
cJSON
module.I use
cJSON_CreateObject()
to get a json object, then add a string field, then generate JSON string. When I executing here, some wrongs occur.This is my SPEC which can trigger the bug:
Error Report
I received the following error report during the fuzzing process:
This is the stack of calls:
It seems there is an illegal access at
/path/to/cJSON.c
in theprint_string_ptr
function. In line 935, and it is the loop'sfor (input_pointer = input; *input_pointer; input_pointer++)
logical fault, you can see the ptrinput_pointer
will not stop until read the '\0', so if the string does not match the specification, which means it doesn't end with '\0', there will be problems with the loop. It will visit the illegal memory.Not only that, but it is also possible that an invalid character was entered, and when the pointer moved to the invalid character, the loop could not process that character.
So the loop should add a check on the range of the string and an exception for invalid characters.
Expected Behavior
The program should execute without any memory errors or crashes.
Actual Behavior
The program crashes with a KASAN report indicating a heap-out-of-bounds error.
Additional Information
It would be greatly appreciated if you could review this bug report. Any suggestions or feedback you can provide would be very helpful. Thank you for your time.
The text was updated successfully, but these errors were encountered: