Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f1f6737

Browse files
committed
Fix incorrect logic in JSON number lexer
Detectable by gcc -Wlogical-op. Add two regression test cases that would previously allow incorrect values to pass.
1 parent fe2534e commit f1f6737

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/backend/utils/adt/json.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ json_lex_number(JsonLexContext *lex, char *s)
541541
if (*s == '.')
542542
{
543543
++s;
544-
if (*s < '0' && *s > '9')
544+
if (*s < '0' || *s > '9')
545545
error = true;
546546
else
547547
{
@@ -558,7 +558,7 @@ json_lex_number(JsonLexContext *lex, char *s)
558558
++s;
559559
if (*s == '+' || *s == '-')
560560
++s;
561-
if (*s < '0' && *s > '9')
561+
if (*s < '0' || *s > '9')
562562
error = true;
563563
else
564564
{

src/test/regress/expected/json.out

+10
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ ERROR: invalid input syntax for type json
113113
LINE 1: SELECT '1f2'::json;
114114
^
115115
DETAIL: line 1: Token "1f2" is invalid.
116+
SELECT '0.x1'::json; -- ERROR
117+
ERROR: invalid input syntax for type json
118+
LINE 1: SELECT '0.x1'::json;
119+
^
120+
DETAIL: line 1: Token "0.x1" is invalid.
121+
SELECT '1.3ex100'::json; -- ERROR
122+
ERROR: invalid input syntax for type json
123+
LINE 1: SELECT '1.3ex100'::json;
124+
^
125+
DETAIL: line 1: Token "1.3ex100" is invalid.
116126
-- Arrays.
117127
SELECT '[]'::json; -- OK
118128
json

src/test/regress/sql/json.sql

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ SELECT '9223372036854775808'::json; -- OK, even though it's too large for int8
2222
SELECT '1e100'::json; -- OK
2323
SELECT '1.3e100'::json; -- OK
2424
SELECT '1f2'::json; -- ERROR
25+
SELECT '0.x1'::json; -- ERROR
26+
SELECT '1.3ex100'::json; -- ERROR
2527

2628
-- Arrays.
2729
SELECT '[]'::json; -- OK

0 commit comments

Comments
 (0)