From 6b7fdcb9702516faa3b125431c6212c0ebb3c8a6 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 28 Sep 2007 10:47:19 +0200 Subject: [PATCH] Use safe_strncpy() instead of copy_filename(). The shell has already removed quotes, so we don't need this functionality from copy_filename() --- commands/net.c | 3 ++- include/net.h | 3 --- net/bootp.c | 5 +++-- net/net.c | 13 ------------- 4 files changed, 5 insertions(+), 19 deletions(-) diff --git a/commands/net.c b/commands/net.c index 2f1bf1360..99fc8703a 100644 --- a/commands/net.c +++ b/commands/net.c @@ -32,6 +32,7 @@ #include #include #include +#include static int netboot_common (proto_t, cmd_tbl_t *, int , char *[]); @@ -182,7 +183,7 @@ netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[]) return 1; } - copy_filename (BootFile, argv[2], sizeof(BootFile)); + safe_strncpy (BootFile, argv[2], sizeof(BootFile)); if ((size = NetLoop(proto)) < 0) return 1; diff --git a/include/net.h b/include/net.h index 8507360c6..3bc712e38 100644 --- a/include/net.h +++ b/include/net.h @@ -424,9 +424,6 @@ IPaddr_t getenv_IPaddr (char *); /* read a VLAN id from an environment variable */ ushort getenv_VLAN(char *); -/* copy a filename (allow for "..." notation, limit length) */ -void copy_filename (char *dst, char *src, int size); - int string_to_enet_addr(const char *str, char *enetaddr); void enet_addr_to_string(const unsigned char *enetaddr, char *str); diff --git a/net/bootp.c b/net/bootp.c index 419a40e2b..7340ed987 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "bootp.h" #include "tftp.h" #include "nfs.h" @@ -106,7 +107,7 @@ static void BootpCopyNetParams(Bootp_t *bp) NetCopyIP(&NetServerIP, &bp->bp_siaddr); memcpy (NetServerEther, ((Ethernet_t *)NetRxPkt)->et_src, 6); if (strlen(bp->bp_file) > 0) - copy_filename (BootFile, bp->bp_file, sizeof(BootFile)); + safe_strncpy (BootFile, bp->bp_file, sizeof(BootFile)); debug ("Bootfile: %s\n", BootFile); @@ -564,7 +565,7 @@ BootpRequest (void) NetWriteIP(&bp->bp_siaddr, 0); NetWriteIP(&bp->bp_giaddr, 0); memcpy (bp->bp_chaddr, NetOurEther, 6); - copy_filename (bp->bp_file, BootFile, sizeof(bp->bp_file)); + safe_strncpy (bp->bp_file, BootFile, sizeof(bp->bp_file)); /* Request additional information from the BOOTP/DHCP server */ #ifdef CONFIG_NET_DHCP diff --git a/net/net.c b/net/net.c index 331269d70..2627a20d7 100644 --- a/net/net.c +++ b/net/net.c @@ -1490,19 +1490,6 @@ NetSetIP(uchar * xip, IPaddr_t dest, int dport, int sport, int len) ip->ip_sum = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2); } -void copy_filename (char *dst, char *src, int size) -{ - if (*src && (*src == '"')) { - ++src; - --size; - } - - while ((--size > 0) && *src && (*src != '"')) { - *dst++ = *src++; - } - *dst = '\0'; -} - char *ip_to_string (IPaddr_t x, char *s) { x = ntohl (x);