[postgis-tickets] r15917 - Undefined behaviour in TYPMOD_GET_SRID
Paul Ramsey
pramsey at cleverelephant.ca
Fri Oct 6 06:18:01 PDT 2017
Author: pramsey
Date: 2017-10-06 06:18:01 -0700 (Fri, 06 Oct 2017)
New Revision: 15917
Modified:
branches/2.2/NEWS
branches/2.2/liblwgeom/cunit/cu_libgeom.c
branches/2.2/liblwgeom/liblwgeom.h.in
Log:
Undefined behaviour in TYPMOD_GET_SRID
Closes #3880
Modified: branches/2.2/NEWS
===================================================================
--- branches/2.2/NEWS 2017-10-06 13:17:46 UTC (rev 15916)
+++ branches/2.2/NEWS 2017-10-06 13:18:01 UTC (rev 15917)
@@ -11,6 +11,7 @@
- #3869, Fix build with "gold" linker
- #3879, Division by zero in some arc cases
- #3878, Single defn of signum in header
+ - #3880, Undefined behaviour in TYPMOD_GET_SRID
PostGIS 2.2.5
Modified: branches/2.2/liblwgeom/cunit/cu_libgeom.c
===================================================================
--- branches/2.2/liblwgeom/cunit/cu_libgeom.c 2017-10-06 13:17:46 UTC (rev 15916)
+++ branches/2.2/liblwgeom/cunit/cu_libgeom.c 2017-10-06 13:18:01 UTC (rev 15917)
@@ -34,6 +34,16 @@
rv = TYPMOD_GET_SRID(typmod);
CU_ASSERT_EQUAL(rv, srid);
+ srid = 999999;
+ TYPMOD_SET_SRID(typmod,srid);
+ rv = TYPMOD_GET_SRID(typmod);
+ CU_ASSERT_EQUAL(rv, srid);
+
+ srid = -999999;
+ TYPMOD_SET_SRID(typmod,srid);
+ rv = TYPMOD_GET_SRID(typmod);
+ CU_ASSERT_EQUAL(rv, srid);
+
srid = SRID_UNKNOWN;
TYPMOD_SET_SRID(typmod,srid);
rv = TYPMOD_GET_SRID(typmod);
Modified: branches/2.2/liblwgeom/liblwgeom.h.in
===================================================================
--- branches/2.2/liblwgeom/liblwgeom.h.in 2017-10-06 13:17:46 UTC (rev 15916)
+++ branches/2.2/liblwgeom/liblwgeom.h.in 2017-10-06 13:18:01 UTC (rev 15917)
@@ -146,7 +146,7 @@
* ZM Flags = Bottom 2 bits.
*/
-#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x1FFFFF00)<<3)>>11)
+#define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
#define TYPMOD_SET_SRID(typmod, srid) ((typmod) = (((typmod) & 0xE00000FF) | ((srid & 0x001FFFFF)<<8)))
#define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
#define TYPMOD_SET_TYPE(typmod, type) ((typmod) = (typmod & 0xFFFFFF03) | ((type & 0x0000003F)<<2))
More information about the postgis-tickets
mailing list