From a389fd3cdce235f271bf0a06177493be84d7ea1b Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 1 Mar 2012 12:25:50 +0000 Subject: [PATCH] Check args passed to ptarray_set_point4d git-svn-id: http://svn.osgeo.org/postgis/trunk@9363 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/liblwgeom.h.in | 1 + liblwgeom/lwgeom_api.c | 2 ++ liblwgeom/ptarray.c | 6 +++--- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/liblwgeom/liblwgeom.h.in b/liblwgeom/liblwgeom.h.in index 1623413d4..9b7ae80f5 100644 --- a/liblwgeom/liblwgeom.h.in +++ b/liblwgeom/liblwgeom.h.in @@ -770,6 +770,7 @@ extern int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point); * dimension, the appropriate ordinate values * will be extracted from it * + * N must be a valid point index */ extern void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d); diff --git a/liblwgeom/lwgeom_api.c b/liblwgeom/lwgeom_api.c index 78edb496b..8c46bd166 100644 --- a/liblwgeom/lwgeom_api.c +++ b/liblwgeom/lwgeom_api.c @@ -17,6 +17,7 @@ #include #include #include +#include /* * Lower this to reduce integrity checks @@ -457,6 +458,7 @@ getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point) void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d) { + assert(n >= 0 && n < pa->npoints); uint8_t *ptr=getPoint_internal(pa, n); switch ( FLAGS_GET_ZM(pa->flags) ) { diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c index 53fdab043..b623c02e2 100644 --- a/liblwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -125,13 +125,13 @@ ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, int where) LWDEBUGF(5,"copying %d bytes to start vertex %d from start vertex %d", copy_size, where+1, where); } + /* We have one more point */ + ++pa->npoints; + /* Copy the new point into the gap */ ptarray_set_point4d(pa, where, p); LWDEBUGF(5,"copying new point to start vertex %d", point_size, where); - /* We have one more point */ - pa->npoints++; - return LW_SUCCESS; } -- 2.40.0