Skip to content

Commit 716a6c2

Browse files
qwertystarsCopilot
andcommitted
Fix decode_pointer_inplace ~1 escape and minify_string escape handling
Two bugs fixed: 1. cJSON_Utils.c decode_pointer_inplace(): The ~1 JSON Pointer escape (RFC 6901 §3) was writing to decoded_string[1] instead of decoded_string[0], causing incorrect decoding. Additionally, non-escape characters after escape sequences were not being copied when the decoded output pointer fell behind the input pointer. This caused JSON Patch operations with ~1 in paths to silently fail or operate on wrong keys. 2. cJSON.c minify_string(): The escape handling only checked for \" (escaped quote) but not \\ (escaped backslash) or other escapes. A string ending with \\ caused the closing quote to be misidentified as an escaped quote, making the function read past the string boundary and absorb subsequent JSON tokens into the string value. Both fixes are minimal and include bounds checking. All 19 existing tests pass with these changes. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b2890c8 commit 716a6c2

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

cJSON.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2913,7 +2913,7 @@ static void minify_string(char **input, char **output) {
29132913
*input += static_strlen("\"");
29142914
*output += static_strlen("\"");
29152915
return;
2916-
} else if (((*input)[0] == '\\') && ((*input)[1] == '\"')) {
2916+
} else if (((*input)[0] == '\\') && ((*input)[1] != '\0')) {
29172917
(*output)[1] = (*input)[1];
29182918
*input += static_strlen("\"");
29192919
*output += static_strlen("\"");

cJSON_Utils.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ static void decode_pointer_inplace(unsigned char *string)
374374
}
375375
else if (string[1] == '1')
376376
{
377-
decoded_string[1] = '/';
377+
decoded_string[0] = '/';
378378
}
379379
else
380380
{
@@ -384,6 +384,10 @@ static void decode_pointer_inplace(unsigned char *string)
384384

385385
string++;
386386
}
387+
else
388+
{
389+
decoded_string[0] = string[0];
390+
}
387391
}
388392

389393
decoded_string[0] = '\0';

0 commit comments

Comments
 (0)