ethtool.c:fix buffer overflow when devname is too long
Subsystems (2)
PATCH 1/1 ethtool.c:fix buffer overflow when devname is too long
As the length of field ifr_name of struct ifreq is IFNAMSIZ(16) in header file /usr/include/net/if.h. It will result in buffer overflow when devname is too long. Modified strcpy to strncpy for only copying IFNAMSIZ bytes into struct ifreq. Also, by adding a section into parse_cmdline to detect if the length of devname is invalid.
ethtool.c +4 -1
@@ -626,6 +626,9 @@ static void parse_cmdline(int argc, charif (devname ==NULL ) {show_usage (1 ); + }else if (strlen (devname) >IFNAMSIZ ) { +fprintf (stderr,"Device name is too long. Should be less than %d!\n" ,IFNAMSIZ ); +show_usage (1 ); } }
@@ -1139,7 +1142,7 @@ static int doit(void)/* Setup our control structures. */ memset (&ifr,0 ,sizeof (ifr)); -strcpy (ifr.ifr_name, devname); +strncpy (ifr.ifr_name, devname,IFNAMSIZ );/* Open control socket. */ fd =socket (AF_INET ,SOCK_DGRAM ,0 );
Quoted 3 lines · [email protected] wrote:
As the length of field
ifr_nameof struct ifreq is IFNAMSIZ(16) in header file/usr/include/net/if.h. It will result in buffer overflow when devname is too long. Modified strcpy to strncpy for only copying IFNAMSIZ bytes into struct ifreq. Also, by adding a section intoparse_cmdlineto detect if the length of devname is invalid.Signed-off-by Zhao Yu Wang <[email protected]>
There's already a patch checked into ethtool.git for this...
Jeff