From 735614168cebb751f60c95af62c45c971ded3e49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20J=2E=20Saraiva?= Date: Sun, 24 Mar 2024 17:20:44 +0000 Subject: [PATCH] Fix buffer overflow in lnx_eth_get_dev_index. If the name was longer than IFNAMSIZ then it would corrupt data. --- common/linux_eth.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/linux_eth.c b/common/linux_eth.c index 92ec2a70a..782a80e92 100644 --- a/common/linux_eth.c +++ b/common/linux_eth.c @@ -46,7 +46,8 @@ int lnx_eth_get_dev_index(char *name) } memset((void *)&if_req,0,sizeof(if_req)); - strcpy(if_req.ifr_name,name); + strncpy(if_req.ifr_name,name,IFNAMSIZ-1); + if_req.ifr_name[IFNAMSIZ-1] = '\0'; if (ioctl(fd,SIOCGIFINDEX,&if_req) < 0) { fprintf(stderr,"eth_get_dev_index: SIOCGIFINDEX: %s\n",strerror(errno));