From: Wang Chen <wangchen@cn.fujitsu.com>
To: Ben Hutchings <bhutchings@solarflare.com>,
"David S. Miller" <davem@davemloft.net>
Cc: NETDEV <netdev@vger.kernel.org>
Subject: V2 [PATCH] netdevice: Fix wrong string handle in kernel command line parsing
Date: Tue, 01 Jul 2008 08:56:40 +0800 [thread overview]
Message-ID: <486980C8.80706@cn.fujitsu.com> (raw)
In-Reply-To: <20080630102502.GG4050@solarflare.com>
Ben Hutchings said the following on 2008-6-30 18:25:
>> - strcpy(s[i].name, name);
>> + strncpy(s[i].name, name, IFNAMSIZ);
>
> I think that strncpy() should be strlcpy(), because strncpy() does not
> ensure null-termination.
>
Of course. Thanks, Ben.
v1->v2: Use strlcpy() to ensure s[i].name be null-termination.
1. In netdev_boot_setup_add(), a long name will leak.
ex. : dev=21,0x1234,0x1234,0x2345,eth123456789verylongname.........
2. In netdev_boot_setup_check(), mismatch will happen if s[i].name
is a substring of dev->name.
ex. : dev=...eth1 dev=...eth11
Signed-off-by: Wang Chen <wangchen@cn.fujitsu.com>
---
diff --git a/net/core/dev.c b/net/core/dev.c
index c421a1f..3360df6 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -454,7 +454,7 @@ static int netdev_boot_setup_add(char *name, struct ifmap *map)
for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
if (s[i].name[0] == '\0' || s[i].name[0] == ' ') {
memset(s[i].name, 0, sizeof(s[i].name));
- strcpy(s[i].name, name);
+ strlcpy(s[i].name, name, IFNAMSIZ);
memcpy(&s[i].map, map, sizeof(s[i].map));
break;
}
@@ -479,7 +479,7 @@ int netdev_boot_setup_check(struct net_device *dev)
for (i = 0; i < NETDEV_BOOT_SETUP_MAX; i++) {
if (s[i].name[0] != '\0' && s[i].name[0] != ' ' &&
- !strncmp(dev->name, s[i].name, strlen(s[i].name))) {
+ !strcmp(dev->name, s[i].name)) {
dev->irq = s[i].map.irq;
dev->base_addr = s[i].map.base_addr;
dev->mem_start = s[i].map.mem_start;
next prev parent reply other threads:[~2008-07-01 1:01 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-30 5:22 [PATCH] netdevice: Fix wrong string handle in kernel command line parsing Wang Chen
2008-06-30 10:25 ` Ben Hutchings
2008-07-01 0:56 ` Wang Chen [this message]
2008-07-02 2:57 ` V2 " David Miller
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=486980C8.80706@cn.fujitsu.com \
--to=wangchen@cn.fujitsu.com \
--cc=bhutchings@solarflare.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.