netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@osdl.org>
To: Stephen Hemminger <shemminger@osdl.org>
Cc: David Miller <davem@davemloft.net>,
	xavier.bestel@free.fr, 7eggert@gmx.de, cate@debian.org,
	7eggert@elstempel.de, mitch.a.williams@intel.com,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] net: restrict device names from having whitespace
Date: Thu, 17 Aug 2006 23:11:27 -0700	[thread overview]
Message-ID: <20060817231127.6438324e@localhost.localdomain> (raw)
In-Reply-To: <44E68C4E.8070607@osdl.org>

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

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
---
 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


  reply	other threads:[~2006-08-18  6:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <6Kd5j-3Y7-3@gated-at.bofh.it>
     [not found] ` <6KdRL-5xP-7@gated-at.bofh.it>
     [not found]   ` <6Ke1p-5N8-7@gated-at.bofh.it>
     [not found]     ` <6KekO-6u0-25@gated-at.bofh.it>
     [not found]       ` <6KeXv-7qe-17@gated-at.bofh.it>
     [not found]         ` <6KfTz-OX-11@gated-at.bofh.it>
     [not found]           ` <6KfTA-OX-15@gated-at.bofh.it>
2006-08-16  0:02             ` bonding: cannot remove certain named devices Bodo Eggert
2006-08-16  0:10               ` David Miller
2006-08-16  6:35                 ` Giacomo A. Catenazzi
2006-08-16 13:38                   ` Bill Nottingham
2006-08-16 13:59                     ` Giacomo A. Catenazzi
2006-08-16 15:11                     ` Bodo Eggert
2006-08-17  7:29                       ` Xavier Bestel
2006-08-17 14:12                         ` Bill Nottingham
2006-08-17 23:23                         ` David Miller
2006-08-18  0:34                           ` Alan Cox
2006-08-18  1:01                             ` David Miller
2006-08-18  2:20                           ` Bill Nottingham
2006-08-19  3:58                             ` Stephen Hemminger
2006-08-18  6:11                               ` Stephen Hemminger [this message]
2006-08-18  6:36                                 ` [PATCH] net: restrict device names from having whitespace David Miller
2006-08-18  7:17                                 ` Xavier Bestel
2006-08-18  9:32                                   ` Xavier Bestel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060817231127.6438324e@localhost.localdomain \
    --to=shemminger@osdl.org \
    --cc=7eggert@elstempel.de \
    --cc=7eggert@gmx.de \
    --cc=cate@debian.org \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mitch.a.williams@intel.com \
    --cc=netdev@vger.kernel.org \
    --cc=xavier.bestel@free.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).