canerrsim: main(): avoid buffer overflow: check length of interface name

Closes: https://github.com/linux-can/can-utils/issues/623
pull/624/head
Marc Kleine-Budde 2026-03-09 12:21:51 +01:00
parent 9d4f3c82a2
commit 9e444073b1
1 changed files with 3 additions and 0 deletions

View File

@ -538,6 +538,9 @@ int main(int argc, char *argv[])
err_exit("Error while opening socket\n");
// set interface name
if (strlen(argv[1]) >= IFNAMSIZ)
err_exit("Name of CAN device '%s' is too long!\n\n", argv[1]);
strcpy(ifr.ifr_name, argv[1]); // can0, vcan0...
if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0)
err_exit("Error setting CAN interface name %s\n", argv[1]);