Skip to contentSkip to conversation

ipconfig invokes undefined behaviour

PATCH In review Matthew Wilcox 2 participants 2 messages Feb 6, 2005 – Feb 7, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipconfig invokes undefined behaviour

strcpy is undefined if src and dest overlap. That's clearly possible here with a sufficiently deep path on the server. Use memmove instead.

Index: ./net/ipv4/ipconfig.c
===================================================================
RCS file: /var/cvs/linux-2.6/net/ipv4/ipconfig.c,v retrieving revision 1.12

net/ipv4/ipconfig.c +1 -1
diff -u -p -r1.12 ipconfig.c
@@ -1232,7 +1232,7 @@ u32 __init root_nfs_parse_addr(char *nam
 		if (*cp == ':')
 			*cp++ = '\0';
 		addr = in_aton(name);
-		strcpy(name, cp);
+		memmove(name, cp, strlen(cp) + 1);
 	} else
 		addr = INADDR_NONE;
 
Signature · 6 lines
"Next the statesmen will invent cheap lies, putting the blame upon 
the nation that is attacked, and every man will be glad of those
conscience-soothing falsities, and will diligently study them, and refuse
to examine any refutations of them; and thus he will by and by convince 
himself that the war is just, and will thank God for the better sleep 
he enjoys after this process of grotesque self-deception." -- Mark Twain
maintainer
#1 lore raw
Quoted 4 lines · On Sun, 6 Feb 2005 04:47:44 +0000 Matthew Wilcox <[email protected]> wrote:

strcpy is undefined if src and dest overlap. That's clearly possible here with a sufficiently deep path on the server. Use memmove instead.

Thanks a lot Matthew, applied to both 2.4.x and 2.6.x