diff mbox

[1/6] ip/ipnetns: prevent potential string buffer overflow

Message ID 1438863876-1935-1-git-send-email-phil@nwl.cc
State Rejected, archived
Delegated to: stephen hemminger
Headers show

Commit Message

Phil Sutter Aug. 6, 2015, 12:24 p.m. UTC
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 ip/ipnetns.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Stephen Hemminger Aug. 12, 2015, 3:48 p.m. UTC | #1
Rather than chopping the string off, I decided to solve the problem by changing
network namespace cache to use variable length structure.


--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 3b704a4..32b0f51 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -178,7 +178,8 @@  static int netns_map_add(int nsid, char *name)
 		return -ENOMEM;
 	}
 	c->nsid = nsid;
-	strcpy(c->name, name);
+	strncpy(c->name, name, NAME_MAX);
+	c->name[NAME_MAX - 1] = '\0';
 
 	h = NSID_HASH_NSID(nsid);
 	hlist_add_head(&c->nsid_hash, &nsid_head[h]);