Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix incorrect logic in JSON number lexer
authorPeter Eisentraut <peter_e@gmx.net>
Sat, 19 May 2012 23:24:46 +0000 (02:24 +0300)
committerPeter Eisentraut <peter_e@gmx.net>
Sat, 19 May 2012 23:24:46 +0000 (02:24 +0300)
Detectable by gcc -Wlogical-op.

Add two regression test cases that would previously allow incorrect
values to pass.

src/backend/utils/adt/json.c
src/test/regress/expected/json.out
src/test/regress/sql/json.sql

index 2968c57e3f88e15e3ff1026d5dc1985b09a3b63a..8ab47defbe47075728235c0e1c06d4d69b46118f 100644 (file)
@@ -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
        {
index a26c64a599d7e8b3df445844ffc46f20d29592a1..ed8b237076270087f1e5a93c7adf0d8fd3e2d003 100644 (file)
@@ -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 
index 27454ad362361eff818874a08b3dbdf57255fa2c..52be0cf7eb76364724946e6fdba358a3c576568f 100644 (file)
@@ -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