Subject: [PATCH] net: restrict device names from having whitespace

From: Stephen Hemminger <[email-masked]>
Date: Thu, 17 Aug 2006 23:11:27 -0700

Don't allow spaces in network device names because it makes
it difficult to provide text interfaces via sysfs.

Signed-off-by: Stephen Hemminger <[email-masked]>
---
 net/core/dev.c |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index d95e262..56c8afb 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -79,6 +79,7 @@ #include <linux/capability.h>
 #include <linux/cpu.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
+#include <linux/ctype.h>
 #include <linux/sched.h>
 #include <linux/mutex.h>
 #include <linux/string.h>
@@ -636,10 +637,25 @@ struct net_device * dev_get_by_flags(uns
  */
 int dev_valid_name(const char *name)
 {
-	return !(*name == '\0' 
-		 || !strcmp(name, ".")
-		 || !strcmp(name, "..")
-		 || strchr(name, '/'));
+	if (*name == '\0')	 /* null string */
+		return 0;
+
+	if (*name == '.') {
+		if (name[1] == '\0')	/* can't have . in directory */
+			return 0;
+		if (name[1] == '.' && name[2] == '\0')
+			return 0;	/* or .. */
+	}
+
+	/* Check for blanks and slash because it confuses sysfs interfaces */
+	do {
+		if (*name == '/')
+			return 0;
+		if (isspace(*name))
+			return 0;
+	} while (*++name);
+
+	return 1;
 }
 
 /**
-- 
1.4.0