From: Sandro Santilli Date: Tue, 18 Apr 2006 10:28:48 +0000 (+0000) Subject: Cleanly handled deserialization of points with non-point input by raising an error... X-Git-Tag: pgis_1_1_3~74 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9e3da16025c1b9f7b0cedc0d0f22570dc91b57cd;p=postgis Cleanly handled deserialization of points with non-point input by raising an error. Made other simple geoms deserializers errors of this kind be consistent. Added a check in lwgeom_typename() to avoid memory corruption when input geometrytype is out of range. git-svn-id: http://svn.osgeo.org/postgis/trunk@2330 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/lwgeom/liblwgeom.c b/lwgeom/liblwgeom.c index ab0cd4f4d..ed656ce87 100644 --- a/lwgeom/liblwgeom.c +++ b/lwgeom/liblwgeom.c @@ -112,6 +112,11 @@ default_errorreporter(const char *fmt, ...) const char * lwgeom_typename(int type) { + // something went wrong somewhere + if ( type < 0 || type > 7 ) { + // assert(0); + return "Invalid type"; + } return lwgeomTypeName[type]; } diff --git a/lwgeom/lwline.c b/lwgeom/lwline.c index 3716e0762..1191c2359 100644 --- a/lwgeom/lwline.c +++ b/lwgeom/lwline.c @@ -50,7 +50,7 @@ lwline_deserialize(uchar *serialized_form) if ( lwgeom_getType(type) != LINETYPE) { - lwerror("lwline_deserialize: attempt to deserialize a line when its not really a line"); + lwerror("lwline_deserialize: attempt to deserialize a line which is really a %s", lwgeom_typename(type)); return NULL; } diff --git a/lwgeom/lwpoint.c b/lwgeom/lwpoint.c index 272166cff..9b556ab83 100644 --- a/lwgeom/lwpoint.c +++ b/lwgeom/lwpoint.c @@ -256,7 +256,11 @@ lwpoint_deserialize(uchar *serialized_form) type = serialized_form[0]; - if ( lwgeom_getType(type) != POINTTYPE) return NULL; + if ( lwgeom_getType(type) != POINTTYPE) + { + lwerror("lwpoint_deserialize: attempt to deserialize a point which is really a %s", lwgeom_typename(type)); + return NULL; + } result->type = type; loc = serialized_form+1; diff --git a/lwgeom/lwpoly.c b/lwgeom/lwpoly.c index d013a13ce..606bed1a1 100644 --- a/lwgeom/lwpoly.c +++ b/lwgeom/lwpoly.c @@ -84,8 +84,7 @@ lwpoly_deserialize(uchar *serialized_form) if ( TYPE_GETTYPE(type) != POLYGONTYPE) { - lwerror("lwpoly_deserialize called with arg of type %d", - lwgeom_getType(type)); + lwerror("lwpoly_deserialize: attempt to deserialize a poly which is really a %s", lwgeom_typename(type)); return NULL; }