[BusyBox] bug in 'dump.c'

David Updegraff dave at cray.com
Thu Feb 13 09:44:03 UTC 2003


Hi.

Crosscompiling for powerpc, I found that the 'xmalloc()'s of
linked list entities were not being zero'd by default, leading
to segfaults.  Using 'calloc' instead fixed the problem.  Could
someone with cvs-write access consider below patch?

---------snip-------

diff -u -r1.3 dump.c
--- dump.c	22 Aug 2002 18:39:08 -0000	1.3
+++ dump.c	13 Feb 2003 16:42:10 -0000
@@ -122,11 +122,13 @@
  		 */
  		for (nconv = 0, fmtp = fu->fmt; *fmtp; nextpr = &pr->nextpr) {
  			/* NOSTRICT */
-			pr = (PR *) xmalloc(sizeof(PR));
+			/* use calloc so that forward ptrs start out NULL*/
+			pr = (PR *) xcalloc(1,sizeof(PR));
  			if (!fu->nextpr)
  				fu->nextpr = pr;
-			else
-				*nextpr = pr;
+			/* ignore nextpr -- its unused inside the loop and is
+			 * uninitialized 1st time thru.
+			 */

  			/* skip preceding text and up to the next % sign */
  			for (p1 = fmtp; *p1 && *p1 != '%'; ++p1);
@@ -763,7 +765,8 @@

  	/* start new linked list of format units */
  	/* NOSTRICT */
-	tfs = (FS *) xmalloc(sizeof(FS));
+	/* use calloc so that forward pointers start out NULL */
+	tfs = (FS *) xcalloc(1,sizeof(FS));
  	if (!fshead) {
  		fshead = tfs;
  	} else {
@@ -782,7 +785,8 @@

  		/* allocate a new format unit and link it in */
  		/* NOSTRICT */
-		tfu = (FU *) xmalloc(sizeof(FU));
+		/* use calloc so that forward pointers start out NULL */
+		tfu = (FU *) xcalloc(1,sizeof(FU));
  		*nextfu = tfu;
  		nextfu = &tfu->nextfu;
  		tfu->reps = 1;


---------------snip------------
-- 
David Updegraff / dave at cray.com / 218-525-1154




More information about the busybox mailing list