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 <mkl@pengutronix.de>pull/386/head
parent
0f7c1aa23a
commit
1f96d674c0
8
cangen.c
8
cangen.c
|
|
@ -321,13 +321,11 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr.can_family = AF_CAN;
|
addr.can_family = AF_CAN;
|
||||||
|
addr.can_ifindex = if_nametoindex(argv[optind]);
|
||||||
strcpy(ifr.ifr_name, argv[optind]);
|
if (!addr.can_ifindex) {
|
||||||
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
|
perror("if_nametoindex");
|
||||||
perror("SIOCGIFINDEX");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
addr.can_ifindex = ifr.ifr_ifindex;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* disable default receive filter on this RAW socket
|
* disable default receive filter on this RAW socket
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue