[Pkg-shadow-commits] r2818 - in upstream/trunk: . libmisc

Nicolas FRANÇOIS nekral-guest at alioth.debian.org
Mon Apr 27 20:07:59 UTC 2009


Author: nekral-guest
Date: 2009-04-27 20:07:59 +0000 (Mon, 27 Apr 2009)
New Revision: 2818

Modified:
   upstream/trunk/ChangeLog
   upstream/trunk/libmisc/env.c
Log:
	* libmisc/env.c: Added assertions on the snprintf results.


Modified: upstream/trunk/ChangeLog
===================================================================
--- upstream/trunk/ChangeLog	2009-04-27 20:06:25 UTC (rev 2817)
+++ upstream/trunk/ChangeLog	2009-04-27 20:07:59 UTC (rev 2818)
@@ -1,5 +1,9 @@
 2009-04-27  Nicolas François  <nicolas.francois at centraliens.net>
 
+	* libmisc/env.c: Added assertions on the snprintf results.
+
+2009-04-27  Nicolas François  <nicolas.francois at centraliens.net>
+
 	* NEWS, configure.in: Added configure option --enable-utmpx,
 	disabled by default. This defines USE_UTMPX, which should be used
 	instead of HAVE_UTMPX_H.

Modified: upstream/trunk/libmisc/env.c
===================================================================
--- upstream/trunk/libmisc/env.c	2009-04-27 20:06:25 UTC (rev 2817)
+++ upstream/trunk/libmisc/env.c	2009-04-27 20:07:59 UTC (rev 2818)
@@ -34,6 +34,7 @@
 
 #ident "$Id$"
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -92,8 +93,11 @@
 	size_t n;
 
 	if (NULL != value) {
-		newstring = xmalloc (strlen (string) + strlen (value) + 2);
-		sprintf (newstring, "%s=%s", string, value);
+		size_t len = strlen (string) + strlen (value) + 2;
+		int wlen;
+		newstring = xmalloc (len);
+		wlen = snprintf (newstring, len, "%s=%s", string, value);
+		assert (wlen == (int) len -1);
 	} else {
 		newstring = xstrdup (string);
 	}
@@ -187,7 +191,10 @@
 
 		cp = strchr (*argv, '=');
 		if (NULL == cp) {
-			snprintf (variable, sizeof variable, "L%d", noname++);
+			int wlen;
+			wlen = snprintf (variable, sizeof variable, "L%d", noname);
+			assert (wlen < (int) sizeof(variable));
+			noname++;
 			addenv (variable, *argv);
 		} else {
 			const char **p;




More information about the Pkg-shadow-commits mailing list