[postgis-tickets] r17059 - Avoid unaligned memory access in BOX2D_out
Raul
raul at rmr.ninja
Thu Nov 22 08:18:14 PST 2018
Author: algunenano
Date: 2018-11-22 08:18:14 -0800 (Thu, 22 Nov 2018)
New Revision: 17059
Modified:
trunk/NEWS
trunk/ci/travis/run_usan_clang.sh
trunk/ci/travis/run_usan_gcc.sh
trunk/postgis/lwgeom_box.c
Log:
Avoid unaligned memory access in BOX2D_out
Also enables UBSan in Travis runs for topology
Closes #4244
Closes https://github.com/postgis/postgis/pull/342
Modified: trunk/NEWS
===================================================================
--- trunk/NEWS 2018-11-22 16:16:23 UTC (rev 17058)
+++ trunk/NEWS 2018-11-22 16:18:14 UTC (rev 17059)
@@ -42,6 +42,7 @@
- #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.0
2018/09/23
Modified: trunk/ci/travis/run_usan_clang.sh
===================================================================
--- trunk/ci/travis/run_usan_clang.sh 2018-11-22 16:16:23 UTC (rev 17058)
+++ trunk/ci/travis/run_usan_clang.sh 2018-11-22 16:18:14 UTC (rev 17059)
@@ -9,6 +9,5 @@
./autogen.sh
# Build with Clang and usan flags
-# TODO: Fix topology ubsan
-./configure CC=clang CFLAGS="${CFLAGS_STD}" LDFLAGS="${LDFLAGS_STD}" --without-topology
+./configure CC=clang CFLAGS="${CFLAGS_STD}" LDFLAGS="${LDFLAGS_STD}"
bash ./ci/travis/logbt -- make -j check RUNTESTFLAGS=--verbose
Modified: trunk/ci/travis/run_usan_gcc.sh
===================================================================
--- trunk/ci/travis/run_usan_gcc.sh 2018-11-22 16:16:23 UTC (rev 17058)
+++ trunk/ci/travis/run_usan_gcc.sh 2018-11-22 16:18:14 UTC (rev 17059)
@@ -9,6 +9,5 @@
./autogen.sh
# Build with GCC and usan flags
-# TODO: Fix topology ubsan
-./configure CC=gcc CFLAGS="${CFLAGS_STD}" LDFLAGS="${LDFLAGS_STD}" --without-topology
+./configure CC=gcc CFLAGS="${CFLAGS_STD}" LDFLAGS="${LDFLAGS_STD}"
bash ./ci/travis/logbt -- make -j check RUNTESTFLAGS=--verbose
Modified: trunk/postgis/lwgeom_box.c
===================================================================
--- trunk/postgis/lwgeom_box.c 2018-11-22 16:16:23 UTC (rev 17058)
+++ trunk/postgis/lwgeom_box.c 2018-11-22 16:18:14 UTC (rev 17059)
@@ -93,14 +93,22 @@
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);
result[size] = '\0';
More information about the postgis-tickets
mailing list