mirror of
https://github.com/linux-can/can-utils.git
synced 2026-09-22 08:06:34 +02:00
treewide: use if_nametoindex to avoid overflows
replaced strcpy(if_name, argv[x]) + ioctl by if_idx = if_nametoindex(argv[x]) to avoid overflows caused by long user input. Signed-off-by: Sven Schmitt <sven.schmitt@gmx.net> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
This commit is contained in:
committed by
Marc Kleine-Budde
parent
8af831f377
commit
f5fb7317aa
+1
-8
@@ -422,7 +422,6 @@ int main(int argc, char **argv)
|
||||
int s; /* can raw socket */
|
||||
struct sockaddr_can addr;
|
||||
struct termios topts;
|
||||
struct ifreq ifr;
|
||||
int select_stdin = 0;
|
||||
int running = 1;
|
||||
int tstamp = 0;
|
||||
@@ -497,13 +496,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
addr.can_family = AF_CAN;
|
||||
|
||||
strcpy(ifr.ifr_name, argv[2]);
|
||||
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
|
||||
perror("SIOCGIFINDEX");
|
||||
return 1;
|
||||
}
|
||||
addr.can_ifindex = ifr.ifr_ifindex;
|
||||
addr.can_ifindex = if_nametoindex(argv[2]);
|
||||
|
||||
/* disable reception of CAN frames until we are opened by 'O' */
|
||||
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
|
||||
|
||||
Reference in New Issue
Block a user