]> granicus.if.org Git - postgis/commitdiff
Avoid unaligned memory access in BOX2D_out
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Thu, 22 Nov 2018 16:14:23 +0000 (16:14 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Thu, 22 Nov 2018 16:14:23 +0000 (16:14 +0000)
References #4244

git-svn-id: http://svn.osgeo.org/postgis/branches/2.3@17056 b70326c6-7e19-0410-871a-916f4a2858ee

NEWS
postgis/lwgeom_box.c

diff --git a/NEWS b/NEWS
index 7ee9be83207d298839143bd139536a8bf9bb70f5..acc17ec6ef2d8cedf28a78287f7a4ade99198250 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -19,6 +19,7 @@ PostGIS 2.3.8
   - #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.3.7
 2018/04/06
index b5a04e1080e0a72fa00d93e3cca318fb8b8dd9cd..dd2b3a45f48be1bfbb6ca00ab4c1637f0a03f57f 100644 (file)
@@ -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);