[GRASS-SVN] r50186 - in grass/branches/develbranch_6/raster/r.support: modcolr modhist

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jan 14 19:41:18 EST 2012


Author: hamish
Date: 2012-01-14 16:41:17 -0800 (Sat, 14 Jan 2012)
New Revision: 50186

Modified:
   grass/branches/develbranch_6/raster/r.support/modcolr/modcolr.c
   grass/branches/develbranch_6/raster/r.support/modhist/modhist.c
Log:
strncpy doesn't always null-terminate (#1315)

Modified: grass/branches/develbranch_6/raster/r.support/modcolr/modcolr.c
===================================================================
--- grass/branches/develbranch_6/raster/r.support/modcolr/modcolr.c	2012-01-15 00:39:55 UTC (rev 50185)
+++ grass/branches/develbranch_6/raster/r.support/modcolr/modcolr.c	2012-01-15 00:41:17 UTC (rev 50186)
@@ -25,7 +25,7 @@
 int main(int argc, char *argv[])
 {
     int stat;
-    char name[64];
+    char name[GNAME_MAX];
     char *mapset;
     struct Colors pcolr;
 
@@ -41,6 +41,7 @@
     }
     else {
 	strncpy(name, argv[1], sizeof(name));
+	name[sizeof(name) - 1] = '\0';
 	if ((mapset = G_find_cell2(name, "")) == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"), name);
     }

Modified: grass/branches/develbranch_6/raster/r.support/modhist/modhist.c
===================================================================
--- grass/branches/develbranch_6/raster/r.support/modhist/modhist.c	2012-01-15 00:39:55 UTC (rev 50185)
+++ grass/branches/develbranch_6/raster/r.support/modhist/modhist.c	2012-01-15 00:41:17 UTC (rev 50186)
@@ -25,7 +25,7 @@
 
 int main(int argc, char *argv[])
 {
-    char name[64];
+    char name[GNAME_MAX];
     char *mapset;
     struct History hist;
 
@@ -42,6 +42,7 @@
     }
     else {
 	strncpy(name, argv[1], sizeof(name));
+	name[sizeof(name) - 1] = '\0';
 	if ((mapset = G_find_cell2(name, G_mapset())) == NULL)
 	    G_fatal_error(_("Raster file [%s] not found. Exiting."), argv[1]);
     }



More information about the grass-commit mailing list