Hi,

After upgrading gcc to 4.5.0, I get segfaults when running the run-parts
applet. The segfault happens in bb_alphasort() during the calls to strcmp().
I debugged this and saw that the pointers passed into strcmp() were both
NULL. Apparently this comes from the act() function, which for some reason
overwrites the elements of the names array. Oddly enough, when I print that
same array at the end of each call to act() the segfault disappears.

FWIW, I came up with the following patch that fixes things, though it is
probably not the preferred way for busybox because it removes the names
variable from the global storage.

Thierry
diff --git a/debianutils/run_parts.c b/debianutils/run_parts.c
index 37e8487..d235fa7 100644
--- a/debianutils/run_parts.c
+++ b/debianutils/run_parts.c
@@ -33,12 +33,10 @@
 #include "libbb.h"
 
 struct globals {
-	char **names;
 	int    cur;
 	char  *cmd[1];
 } FIX_ALIASING;
 #define G (*(struct globals*)&bb_common_bufsiz1)
-#define names (G.names)
 #define cur   (G.cur  )
 #define cmd   (G.cmd  )
 
@@ -77,8 +75,10 @@ static int bb_alphasort(const void *p1, const void *p2)
 	return (option_mask32 & OPT_r) ? -r : r;
 }
 
-static int FAST_FUNC act(const char *file, struct stat *statbuf, void *args UNUSED_PARAM, int depth)
+static int FAST_FUNC act(const char *file, struct stat *statbuf, void *args, int depth)
 {
+	char ***names = args;
+
 	if (depth == 1)
 		return TRUE;
 
@@ -90,9 +90,9 @@ static int FAST_FUNC act(const char *file, struct stat *statbuf, void *args UNUS
 		return SKIP;
 	}
 
-	names = xrealloc_vector(names, 4, cur);
-	names[cur++] = xstrdup(file);
-	/*names[cur] = NULL; - xrealloc_vector did it */
+	*names = xrealloc_vector(*names, 4, cur);
+	(*names)[cur++] = xstrdup(file);
+	/*(*names)[cur] = NULL; - xrealloc_vector did it */
 
 	return TRUE;
 }
@@ -115,6 +115,7 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
 {
 	const char *umask_p = "22";
 	llist_t *arg_list = NULL;
+	char **names = NULL;
 	unsigned n;
 	int ret;
 
@@ -140,7 +141,7 @@ int run_parts_main(int argc UNUSED_PARAM, char **argv)
 			ACTION_RECURSE|ACTION_FOLLOWLINKS,
 			act,            /* file action */
 			act,            /* dir action */
-			NULL,           /* user data */
+			&names,         /* user data */
 			1               /* depth */
 		);
 

Attachment: signature.asc
Description: Digital signature

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to