aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/json.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-06-04 20:43:57 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-06-04 20:43:57 -0400
commit3dd8e596812e3adb72aecafb23fbb6a30836c475 (patch)
tree61d2e9e1b565d0f70704288e0aa60dfaa99c70d0 /src/backend/utils/adt/json.c
parentd9b31e4859df5325b7d3d2cc94b0e907f1cf1d3e (diff)
downloadpostgresql-3dd8e596812e3adb72aecafb23fbb6a30836c475.tar.gz
postgresql-3dd8e596812e3adb72aecafb23fbb6a30836c475.zip
Fix bogus handling of control characters in json_lex_string().
The original coding misbehaved if "char" is signed, and also made the extremely poor decision to print control characters literally when trying to complain about them. Report and patch by Shigeru Hanada. In passing, also fix core dump risk in report_parse_error() should the parse state be something other than what it expects.
Diffstat (limited to 'src/backend/utils/adt/json.c')
-rw-r--r--src/backend/utils/adt/json.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index 8ab47defbe4..61ae62eb8a9 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -419,7 +419,7 @@ json_lex_string(JsonLexContext *lex)
for (s = lex->token_start + 1; *s != '"'; ++s)
{
/* Per RFC4627, these characters MUST be escaped. */
- if (*s < 32)
+ if ((unsigned char) *s < 32)
{
/* A NUL byte marks the (premature) end of the string. */
if (*s == '\0')
@@ -430,8 +430,8 @@ json_lex_string(JsonLexContext *lex)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type json"),
- errdetail_internal("line %d: Character \"%c\" must be escaped.",
- lex->line_number, *s)));
+ errdetail_internal("line %d: Character with value \"0x%02x\" must be escaped.",
+ lex->line_number, (unsigned char) *s)));
}
else if (*s == '\\')
{
@@ -637,7 +637,7 @@ report_parse_error(JsonParseStack *stack, JsonLexContext *lex)
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input syntax for type json: \"%s\"",
lex->input),
- errdetail_internal(detail, lex->line_number, token)));
+ detail ? errdetail_internal(detail, lex->line_number, token) : 0));
}
/*