From b7f088f974c22471c8f513e21b353144f6063402 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 17 Oct 2012 09:45:36 +0000 Subject: [PATCH] Fix buffer overflow in lwgeom_to_geojson (#2052) git-svn-id: http://svn.osgeo.org/postgis/trunk@10448 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/cunit/cu_out_geojson.c | 7 +++++++ liblwgeom/lwout_geojson.c | 2 ++ 2 files changed, 9 insertions(+) diff --git a/liblwgeom/cunit/cu_out_geojson.c b/liblwgeom/cunit/cu_out_geojson.c index 325ffda2a..a3141a0ca 100644 --- a/liblwgeom/cunit/cu_out_geojson.c +++ b/liblwgeom/cunit/cu_out_geojson.c @@ -81,6 +81,13 @@ static void out_geojson_test_precision(void) "POINT(1E300 -1E300)", "{\"type\":\"Point\",\"coordinates\":[1e+300,-1e+300]}", NULL, 0, 0); + + /* huge precision, see http://trac.osgeo.org/postgis/ticket/2052 */ + do_geojson_test( + "POINT(1 2)", + "{\"type\":\"Point\",\"coordinates\":[1,2]}", + NULL, 100, 0); + } diff --git a/liblwgeom/lwout_geojson.c b/liblwgeom/lwout_geojson.c index 1c69717b2..60d2c2e7a 100644 --- a/liblwgeom/lwout_geojson.c +++ b/liblwgeom/lwout_geojson.c @@ -38,6 +38,8 @@ lwgeom_to_geojson(const LWGEOM *geom, char *srs, int precision, int has_bbox) GBOX tmp; int rv; + if ( precision > OUT_MAX_DIGS_DOUBLE ) precision = OUT_MAX_DIGS_DOUBLE; + if (has_bbox) { /* Whether these are geography or geometry, -- 2.40.0