]> granicus.if.org Git - postgis/commitdiff
Move fix further into parser, fix bad test case
authorPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 9 Jan 2019 20:09:19 +0000 (20:09 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Wed, 9 Jan 2019 20:09:19 +0000 (20:09 +0000)
References #4273

git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@17129 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
liblwgeom/cunit/cu_in_wkt.c
liblwgeom/cunit/cu_out_x3d.c
liblwgeom/lwin_wkt_parse.c

diff --git a/NEWS b/NEWS
index 84d12d7f2ca120d30bdfa3a70663b6872153754d..9527258c5bf2321383044ba7a0ae74b829f5e4a1 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,8 @@ XXXX/XX/XX
 
   - #4276, ST_AsGeoJSON documentation refresh (Darafei Praliaskouski)       
 
+  - #4273, Tighter parsing of WKT (Paul Ramsey)
+
 
 PostGIS 2.5.1
 2018/11/18
index 644136c2b4c70d498b37348d0b3d632b357a0268..2faeb7ea9be21b90cf363f42d99f0ec03a26d6bf 100644 (file)
@@ -67,6 +67,11 @@ static char* cu_wkt_in(char *wkt, uint8_t variant)
 
 static void test_wkt_in_point(void)
 {
+       s = "POINT(1 2) foobar";
+       r = cu_wkt_in(s, WKT_SFSQL);
+       CU_ASSERT_STRING_EQUAL("parse error - invalid geometry", r);
+       lwfree(r);
+
        s = "POINT(1e700 0)";
        r = cu_wkt_in(s, WKT_SFSQL);
        CU_TEST ( ! strcmp(r, "POINT(inf 0)") || ! strcmp(r, "POINT(1.#INF 0)") || ! strcmp(r, "POINT(Infinity 0)") );
index a424e2b5d87b15eaaf5b290d147b7cee437f840f..49f63f5a2ce5289424af612d5d51a8eb0f0605bf 100644 (file)
@@ -77,7 +77,7 @@ static void out_x3d3_test_precision(void)
 
        /* huge data */
        do_x3d3_test(
-           "POINT(1E300 -105E-153 4E300)'", "1e+300 0 4e+300", NULL, 0, 0);
+           "POINT(1E300 -105E-153 4E300)", "1e+300 0 4e+300", NULL, 0, 0);
 }
 
 
index 0f1c30aff551a8d9e4c44ce4ab889db2feee78a7..9a62aa1ceff05da23967aeb2a9b0cf00d5a8b3b3 100644 (file)
@@ -95,16 +95,16 @@ LWGEOM_PARSER_RESULT global_parser_result;
 /* Turn on/off verbose parsing (turn off for production) */
 int wkt_yydebug = 0;
 
-/* 
-* Error handler called by the bison parser. Mostly we will be 
+/*
+* Error handler called by the bison parser. Mostly we will be
 * catching our own errors and filling out the message and errlocation
-* from WKT_ERROR in the grammar, but we keep this one 
+* from WKT_ERROR in the grammar, but we keep this one
 * around just in case.
 */
 void wkt_yyerror(__attribute__((__unused__)) const char *str)
 {
        /* If we haven't already set a message and location, let's set one now. */
-       if ( ! global_parser_result.message ) 
+       if ( ! global_parser_result.message )
        {
                global_parser_result.message = parser_error_messages[PARSER_ERROR_OTHER];
                global_parser_result.errcode = PARSER_ERROR_OTHER;
@@ -137,14 +137,14 @@ int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int pars
        /* Set the input text string, and parse checks. */
        global_parser_result.wkinput = wktstr;
        global_parser_result.parser_check_flags = parser_check_flags;
-               
+
        wkt_lexer_init(wktstr); /* Lexer ready */
        parse_rv = wkt_yyparse(); /* Run the parse */
        LWDEBUGF(4,"wkt_yyparse returned %d", parse_rv);
        wkt_lexer_close(); /* Clean up lexer */
-       
+
        /* A non-zero parser return is an error. */
-       if ( parse_rv != 0 ) 
+       if ( parse_rv || global_parser_result.errcode )
        {
                if( ! global_parser_result.errcode )
                {
@@ -153,17 +153,17 @@ int lwgeom_parse_wkt(LWGEOM_PARSER_RESULT *parser_result, char *wktstr, int pars
                        global_parser_result.errlocation = wkt_yylloc.last_column;
                }
 
-               LWDEBUGF(5, "error returned by wkt_yyparse() @ %d: [%d] '%s'", 
-                           global_parser_result.errlocation, 
-                           global_parser_result.errcode, 
+               LWDEBUGF(5, "error returned by wkt_yyparse() @ %d: [%d] '%s'",
+                           global_parser_result.errlocation,
+                           global_parser_result.errcode,
                            global_parser_result.message);
-               
+
                /* Copy the global values into the return pointer */
                *parser_result = global_parser_result;
                 wkt_yylex_destroy();
                return LW_FAILURE;
        }
-       
+
        /* Copy the global value into the return pointer */
        *parser_result = global_parser_result;
         wkt_yylex_destroy();