From: Raúl Marín Rodríguez Date: Thu, 22 Nov 2018 16:16:23 +0000 (+0000) Subject: Avoid unaligned memory access in BOX2D_out X-Git-Tag: 2.5.2~50 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f062a45804e6bf1a88c5509fc81017d8208ed48f;p=postgis Avoid unaligned memory access in BOX2D_out References #4244 git-svn-id: http://svn.osgeo.org/postgis/branches/2.5@17058 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/NEWS b/NEWS index 383c5b778..9aa58fa97 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,7 @@ XXXX/XX/XX - #4247, Avoid undefined behaviour in next_float functions (Raúl Marín) - #4249, Fix undefined behaviour in raster intersection (Raúl Marín) - #4246, Fix undefined behaviour in ST_3DDistance (Raúl Marín) + - #4244, Avoid unaligned memory access in BOX2D_out (Raúl Marín) PostGIS 2.5.1 2018/11/18 diff --git a/postgis/lwgeom_box.c b/postgis/lwgeom_box.c index 92a663524..3c0b99ed2 100644 --- a/postgis/lwgeom_box.c +++ b/postgis/lwgeom_box.c @@ -95,13 +95,21 @@ Datum BOX2D_in(PG_FUNCTION_ARGS) PG_FUNCTION_INFO_V1(BOX2D_out); Datum BOX2D_out(PG_FUNCTION_ARGS) { - GBOX *box = (GBOX *) PG_GETARG_POINTER(0); char tmp[500]; /* big enough */ char *result; int size; - size = sprintf(tmp,"BOX(%.15g %.15g,%.15g %.15g)", - box->xmin, box->ymin, box->xmax, box->ymax); + GBOX *box = (GBOX *)PG_GETARG_POINTER(0); + /* Avoid unaligned access to the gbox struct */ + GBOX box_aligned; + memcpy(&box_aligned, box, sizeof(GBOX)); + + size = sprintf(tmp, + "BOX(%.15g %.15g,%.15g %.15g)", + box_aligned.xmin, + box_aligned.ymin, + box_aligned.xmax, + box_aligned.ymax); result= palloc(size+1); /* +1= null term */ memcpy(result,tmp,size+1);