aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2012-05-20 02:24:46 +0300
committerPeter Eisentraut <peter_e@gmx.net>2012-05-20 02:24:46 +0300
commitf1f6737e154f9d00f1565fc08fd7ac677b380822 (patch)
tree77829e4b815df4db51164422fc7426a944ef8eee /src
parentfe2534e534c0572a71d6f0d2d51a2d058fc3524c (diff)
downloadpostgresql-f1f6737e154f9d00f1565fc08fd7ac677b380822.tar.gz
postgresql-f1f6737e154f9d00f1565fc08fd7ac677b380822.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/utils/adt/json.c4
-rw-r--r--src/test/regress/expected/json.out10
-rw-r--r--src/test/regress/sql/json.sql2
3 files changed, 14 insertions, 2 deletions
diff --git a/src/backend/utils/adt/json.c b/src/backend/utils/adt/json.c
index 2968c57e3f8..8ab47defbe4 100644
--- a/src/backend/utils/adt/json.c
+++ b/src/backend/utils/adt/json.c
@@ -541,7 +541,7 @@ json_lex_number(JsonLexContext *lex, char *s)
if (*s == '.')
{
++s;
- if (*s < '0' && *s > '9')
+ if (*s < '0' || *s > '9')
error = true;
else
{
@@ -558,7 +558,7 @@ json_lex_number(JsonLexContext *lex, char *s)
++s;
if (*s == '+' || *s == '-')
++s;
- if (*s < '0' && *s > '9')
+ if (*s < '0' || *s > '9')
error = true;
else
{
diff --git a/src/test/regress/expected/json.out b/src/test/regress/expected/json.out
index a26c64a599d..ed8b2370762 100644
--- a/src/test/regress/expected/json.out
+++ b/src/test/regress/expected/json.out
@@ -113,6 +113,16 @@ ERROR: invalid input syntax for type json
LINE 1: SELECT '1f2'::json;
^
DETAIL: line 1: Token "1f2" is invalid.
+SELECT '0.x1'::json; -- ERROR
+ERROR: invalid input syntax for type json
+LINE 1: SELECT '0.x1'::json;
+ ^
+DETAIL: line 1: Token "0.x1" is invalid.
+SELECT '1.3ex100'::json; -- ERROR
+ERROR: invalid input syntax for type json
+LINE 1: SELECT '1.3ex100'::json;
+ ^
+DETAIL: line 1: Token "1.3ex100" is invalid.
-- Arrays.
SELECT '[]'::json; -- OK
json
diff --git a/src/test/regress/sql/json.sql b/src/test/regress/sql/json.sql
index 27454ad3623..52be0cf7eb7 100644
--- a/src/test/regress/sql/json.sql
+++ b/src/test/regress/sql/json.sql
@@ -22,6 +22,8 @@ SELECT '9223372036854775808'::json; -- OK, even though it's too large for int8
SELECT '1e100'::json; -- OK
SELECT '1.3e100'::json; -- OK
SELECT '1f2'::json; -- ERROR
+SELECT '0.x1'::json; -- ERROR
+SELECT '1.3ex100'::json; -- ERROR
-- Arrays.
SELECT '[]'::json; -- OK