svn commit: trunk/busybox/procps

vda at busybox.net vda at busybox.net
Wed Oct 15 09:43:36 UTC 2008


Author: vda
Date: 2008-10-15 02:43:35 -0700 (Wed, 15 Oct 2008)
New Revision: 23687

Log:
sysctl: fix bug 3894 _for real_.



Modified:
   trunk/busybox/procps/sysctl.c


Changeset:
Modified: trunk/busybox/procps/sysctl.c
===================================================================
--- trunk/busybox/procps/sysctl.c	2008-10-15 08:53:19 UTC (rev 23686)
+++ trunk/busybox/procps/sysctl.c	2008-10-15 09:43:35 UTC (rev 23687)
@@ -234,19 +234,30 @@
 
 static void sysctl_dots_to_slashes(char *name)
 {
-	char *cptr = name;
+	char *cptr, *last_good;
+	char *end = name + strlen(name) - 1;
 
 	/* Example from bug 3894:
 	 * net.ipv4.conf.eth0.100.mc_forwarding ->
-	 * net/ipv4/conf/eth0.100/mc_forwarding */
-	while (*cptr != '\0') {
+	 * net/ipv4/conf/eth0.100/mc_forwarding. NB:
+	 * net/ipv4/conf/eth0/mc_forwarding *also exists*,
+	 * therefore we must start from the end, and if
+	 * we replaced even one . -> /, start over again,
+	 * but never replace dots before the position
+	 * where replacement occurred. */
+	last_good = name - 1;
+ again:
+	cptr = end;
+	while (cptr > last_good) {
 		if (*cptr == '.') {
 			*cptr = '\0';
-			if (access(name, F_OK) == 0)
+			if (access(name, F_OK) == 0) {
 				*cptr = '/';
-			else
-				*cptr = '.';
+				last_good = cptr;
+				goto again;
+			}
+			*cptr = '.';
 		}
-		cptr++;
+		cptr--;
 	}
 } /* end sysctl_dots_to_slashes() */




More information about the busybox-cvs mailing list