DaveGamble / cJSON

Ultralightweight JSON parser in ANSI C
MIT License
10.83k stars 3.22k forks source link

fix fail to catch last backslash # 780 #782

Open lxltiger opened 1 year ago

lxltiger commented 1 year ago

static cJSON_bool parse_string(cJSON const item, parse_buffer const input_buffer) { ... // this does not work if ((size_t)(input_end + 1 - input_buffer->content) >= input_buffer->length) { / prevent buffer overflow when last input character is a backslash / goto fail; } ... } image

As show above , when last input character is a backslash.The index of input_end is always input_buffer->length - 2. So input_end + 1 - input_buffer->content >= input_buffer->length will never come true。

Maybe we should minus 1 in the right: input_end + 1 - input_buffer->content >= input_buffer->length-1