[postgis-tickets] [PostGIS] #2956: ST_AsTWKB(NULL) crashes the backend

PostGIS trac at osgeo.org
Mon Oct 6 02:41:31 PDT 2014


#2956: ST_AsTWKB(NULL) crashes the backend
---------------------+------------------------------------------------------
 Reporter:  strk     |       Owner:  nicklas      
     Type:  defect   |      Status:  new          
 Priority:  blocker  |   Milestone:  PostGIS 2.2.0
Component:  postgis  |     Version:  trunk        
 Keywords:           |  
---------------------+------------------------------------------------------

Comment(by strk):

 Right behavior is return null. Here's a quick patch (but needs regress
 test added):
 {{{
 diff --git a/postgis/lwgeom_inout.c b/postgis/lwgeom_inout.c
 index 6bf84f9..d924f3a 100644
 --- a/postgis/lwgeom_inout.c
 +++ b/postgis/lwgeom_inout.c
 @@ -406,7 +406,7 @@ Datum WKBFromLWGEOM(PG_FUNCTION_ARGS)
  PG_FUNCTION_INFO_V1(TWKBFromLWGEOM);
  Datum TWKBFromLWGEOM(PG_FUNCTION_ARGS)
  {
 -       GSERIALIZED *geom =
 (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
 +       GSERIALIZED *geom;
         LWGEOM *lwgeom;
         uint8_t *twkb;
         size_t twkb_size;
 @@ -414,6 +414,10 @@ Datum TWKBFromLWGEOM(PG_FUNCTION_ARGS)
         bytea *result;
         int64_t id;
         int prec;
 +
 +       if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
 +
 +       geom = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));

         /* If user specified precision, respect it */
         if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
 }}}

-- 
Ticket URL: <http://trac.osgeo.org/postgis/ticket/2956#comment:3>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list