mdev : bug corrected (patch attached)

Bernhard Fischer rep.dot.nop at gmail.com
Fri Jun 1 13:57:35 UTC 2007


On Fri, Jun 01, 2007 at 03:15:10PM +0200, Renaud Cerrato wrote:
>Dear,
>
>Using mdev, we noticed that some devices were not attached to /dev/ using
>"mdev -s".
>Looking at the source code, the function which walk through the /sys/ tree
>make use of lstat, but the /sys tree can use symlink as seen here :
>
>$ ls -l /sys/class/misc/
>lrwxrwxrwx    1 root     root            0 Jan  1  1970 watchdog ->
>../../devices/platform/at91sam9x_wdt/watchdog
>
>Doing so, the function can't walk through symbolic links. By replacing lstat
>by stat, the problem is corrected.
>To avoid infinite loop, we added a walking through depth limit to 2 (see
>udevstart.c).
>
>Cheers

>diff -Nru busybox-1.4.1/util-linux/mdev.c busybox-1.4.1_modified/util-linux/mdev.c
>--- busybox-1.4.1/util-linux/mdev.c	2007-01-24 22:34:51.000000000 +0100
>+++ busybox-1.4.1_modified/util-linux/mdev.c	2007-06-01 14:47:07.013533464 +0200
>@@ -14,6 +14,10 @@
> 
> #define DEV_PATH	"/dev"
> 
>+#define MAX_DEPTH	3
>+
>+static int depth;
>+
> struct mdev_globals
> {
> 	int root_major, root_minor;
>@@ -195,18 +199,22 @@
> }
> 
> /* Recursive search of /sys/block or /sys/class.  path must be a writeable
>- * buffer of size PATH_MAX containing the directory string to start at. */
>+ * buffer of size PATH_MAX containing the directory string to start at. 
>+ * The recursive depth is limited to avoid inifinite loop (circular symlinks)
>+ */
> 
> static void find_dev(char *path)
> {
> 	DIR *dir;
> 	size_t len = strlen(path);
> 	struct dirent *entry;
>-
>+		
> 	dir = opendir(path);
> 	if (dir == NULL)
> 		return;
> 
>+	depth++;
>+	
> 	while ((entry = readdir(dir)) != NULL) {
> 		struct stat st;

recursive_action() anyone?




More information about the busybox mailing list