Skip to content

Commit

Permalink
[NET] netdev: Check name length
Browse files Browse the repository at this point in the history
Some improvements to robust name interface.  These API's are safe
now by convention, but it is worth providing some safety checks
against future bugs.

Signed-off-by: Stephen Hemminger <shemminger@osdl.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Stephen Hemminger authored and David S. Miller committed Sep 22, 2006
1 parent 3696f62 commit b6fe17d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion net/core/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ int dev_valid_name(const char *name)
{
if (*name == '\0')
return 0;
if (strlen(name) >= IFNAMSIZ)
return 0;
if (!strcmp(name, ".") || !strcmp(name, ".."))
return 0;

Expand Down Expand Up @@ -3191,13 +3193,15 @@ struct net_device *alloc_netdev(int sizeof_priv, const char *name,
struct net_device *dev;
int alloc_size;

BUG_ON(strlen(name) >= sizeof(dev->name));

/* ensure 32-byte alignment of both the device and private area */
alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST;
alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;

p = kzalloc(alloc_size, GFP_KERNEL);
if (!p) {
printk(KERN_ERR "alloc_dev: Unable to allocate device.\n");
printk(KERN_ERR "alloc_netdev: Unable to allocate device.\n");
return NULL;
}

Expand Down

0 comments on commit b6fe17d

Please sign in to comment.