]> granicus.if.org Git - postgis/commitdiff
Fix undefined behaviour in SADFWrite
authorRaúl Marín Rodríguez <rmrodriguez@carto.com>
Tue, 2 Oct 2018 09:38:48 +0000 (09:38 +0000)
committerRaúl Marín Rodríguez <rmrodriguez@carto.com>
Tue, 2 Oct 2018 09:38:48 +0000 (09:38 +0000)
Also addresses several GCC warnings.

Closes #4189
Closes https://github.com/postgis/postgis/pull/310

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

NEWS
liblwgeom/lwutil.c
loader/pgsql2shp-core.c
loader/safileio.c

diff --git a/NEWS b/NEWS
index 7423db1f3c42ab33114044d3989b896ef1494f87..3c55f454169ed0d31ebbf1861afb17ffc5e4e7b4 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ PostGIS 3.0.0
   - #4181, St_AsMVTGeom: Avoid type changes due to validation (Raúl Marín)
   - #4183, St_AsMVTGeom: Drop invalid geometries after simplification (Raúl Marín)
   - #4188, Avoid division by zero in kmeans (Raúl Marín)
+  - #4189, Fix undefined behaviour in SADFWrite (Raúl Marín)
 
 PostGIS 2.5.0
 2018/09/23
index b9a523c669f7f6d2e266a183d3022bedbdef29e4..52f1720075e083ad000468025e972a3cc1b4d8db 100644 (file)
@@ -280,13 +280,13 @@ char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int
                        {
                                /* Add "..." prefix */
                                outstart = str + endpos + 1 - maxlength + 3;
-                               strncat(output, "...", 3);
+                               strncat(output, "...", 4);
                                strncat(output, outstart, maxlength - 3);
                        }
                        else
                        {
                                /* maxlength is too small; just output "..." */
-                               strncat(output, "...", 3);
+                               strncat(output, "...", 4);
                        }
                }
        }
@@ -307,12 +307,12 @@ char *lwmessage_truncate(char *str, int startpos, int endpos, int maxlength, int
                                /* Add "..." suffix */
                                outstart = str + startpos;
                                strncat(output, outstart, maxlength - 3);
-                               strncat(output, "...", 3);
+                               strncat(output, "...", 4);
                        }
                        else
                        {
                                /* maxlength is too small; just output "..." */
-                               strncat(output, "...", 3);
+                               strncat(output, "...", 4);
                        }
                }
        }
index ffbc613c6b4f80d6826847ee34106d58296826b7..aa9c26b5e07abf15761adda1f972a1218073ee8b 100644 (file)
@@ -1549,7 +1549,7 @@ ShpDumperOpenTable(SHPDUMPERSTATE *state)
                {
                        if (!strncasecmp(dbffieldname, state->dbffieldnames[j], 10))
                        {
-                               sprintf(dbffieldname, "%.7s_%.2d", ptr, tmpint % 100);
+                               sprintf(dbffieldname, "%.7s_%.2d", ptr, abs(tmpint) % 100);
                                tmpint++;
                                continue;
                        }
index 439ebb141f2a707e015468c0f4ff0d229b090c80..ee5a98afbe26a4aaf2ae82c2360de726a92e712a 100644 (file)
@@ -115,8 +115,9 @@ SAOffset SADFRead( void *p, SAOffset size, SAOffset nmemb, SAFile file )
 SAOffset SADFWrite( void *p, SAOffset size, SAOffset nmemb, SAFile file )
 
 {
-    return (SAOffset) fwrite( p, (size_t) size, (size_t) nmemb,
-                              (FILE *) file );
+       if (!nmemb || !p) return 0;
+       return (SAOffset) fwrite( p, (size_t) size, (size_t) nmemb,
+                               (FILE *) file );
 }
 
 /************************************************************************/