Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3dd8e59

Browse files
committed
Fix bogus handling of control characters in json_lex_string().
The original coding misbehaved if "char" is signed, and also made theextremely poor decision to print control characters literally when tryingto complain about them. Report and patch by Shigeru Hanada.In passing, also fix core dump risk in report_parse_error() should theparse state be something other than what it expects.
1 parentd9b31e4 commit3dd8e59

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

‎src/backend/utils/adt/json.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ json_lex_string(JsonLexContext *lex)
419419
for (s=lex->token_start+1;*s!='"';++s)
420420
{
421421
/* Per RFC4627, these characters MUST be escaped. */
422-
if (*s<32)
422+
if ((unsignedchar)*s<32)
423423
{
424424
/* A NUL byte marks the (premature) end of the string. */
425425
if (*s=='\0')
@@ -430,8 +430,8 @@ json_lex_string(JsonLexContext *lex)
430430
ereport(ERROR,
431431
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
432432
errmsg("invalid input syntax for type json"),
433-
errdetail_internal("line %d: Character\"%c\" must be escaped.",
434-
lex->line_number,*s)));
433+
errdetail_internal("line %d: Characterwith value \"0x%02x\" must be escaped.",
434+
lex->line_number,(unsignedchar)*s)));
435435
}
436436
elseif (*s=='\\')
437437
{
@@ -637,7 +637,7 @@ report_parse_error(JsonParseStack *stack, JsonLexContext *lex)
637637
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
638638
errmsg("invalid input syntax for type json: \"%s\"",
639639
lex->input),
640-
errdetail_internal(detail,lex->line_number,token)));
640+
detail ?errdetail_internal(detail,lex->line_number,token) :0));
641641
}
642642

643643
/*

‎src/test/regress/expected/json.out

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ def"'::json;-- ERROR, unescaped newline in string constant
2626
ERROR: invalid input syntax for type json
2727
LINE 1: SELECT '"abc
2828
^
29-
DETAIL: line 1: Character "
30-
" must be escaped.
29+
DETAIL: line 1: Character with value "0x0a" must be escaped.
3130
SELECT '"\n\"\\"'::json;-- OK, legal escapes
3231
json
3332
----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp