From 1f96d674c0cb7b60ee315981f12a7feb94829697 Mon Sep 17 00:00:00 2001 From: Marc Kleine-Budde Date: Sun, 27 Mar 2022 10:53:18 +0200 Subject: [PATCH] cangen: use if_nametoindex() to avoid overflows This patch replaces strcpy() + ioctl() by if_nametoindex() to avoid overflows caused by long user input. Signed-off-by: Marc Kleine-Budde --- cangen.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cangen.c b/cangen.c index 5f7c163..963f9c5 100644 --- a/cangen.c +++ b/cangen.c @@ -321,13 +321,11 @@ int main(int argc, char **argv) } addr.can_family = AF_CAN; - - strcpy(ifr.ifr_name, argv[optind]); - if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { - perror("SIOCGIFINDEX"); + addr.can_ifindex = if_nametoindex(argv[optind]); + if (!addr.can_ifindex) { + perror("if_nametoindex"); return 1; } - addr.can_ifindex = ifr.ifr_ifindex; /* * disable default receive filter on this RAW socket