replaced strcpy(if_name, argv[x]) by if_name=if_nametoindex(argv[x]) to avoid overflows caused by long user input.
parent
47fbe8fec2
commit
83eea54bc7
|
|
@ -312,7 +312,6 @@ static int can_echo_gen(void)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct ifreq ifr;
|
|
||||||
struct sockaddr_can addr;
|
struct sockaddr_can addr;
|
||||||
char *intf_name;
|
char *intf_name;
|
||||||
int family = PF_CAN, type = SOCK_RAW, proto = CAN_RAW;
|
int family = PF_CAN, type = SOCK_RAW, proto = CAN_RAW;
|
||||||
|
|
@ -356,9 +355,7 @@ int main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
addr.can_family = family;
|
addr.can_family = family;
|
||||||
strcpy(ifr.ifr_name, intf_name);
|
addr.can_ifindex = if_nametoindex(intf_name);
|
||||||
ioctl(sockfd, SIOCGIFINDEX, &ifr);
|
|
||||||
addr.can_ifindex = ifr.ifr_ifindex;
|
|
||||||
|
|
||||||
if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
perror("bind");
|
perror("bind");
|
||||||
|
|
|
||||||
11
cansend.c
11
cansend.c
|
|
@ -94,13 +94,14 @@ int main(int argc, char **argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
addr.can_family = AF_CAN;
|
strncpy(ifr.ifr_name, argv[1], IFNAMSIZ);
|
||||||
|
ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name);
|
||||||
strcpy(ifr.ifr_name, argv[1]);
|
if (!ifr.ifr_ifindex) {
|
||||||
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
|
perror("if_nametoindex");
|
||||||
perror("SIOCGIFINDEX");
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addr.can_family = AF_CAN;
|
||||||
addr.can_ifindex = ifr.ifr_ifindex;
|
addr.can_ifindex = ifr.ifr_ifindex;
|
||||||
|
|
||||||
if (required_mtu > CAN_MTU) {
|
if (required_mtu > CAN_MTU) {
|
||||||
|
|
|
||||||
|
|
@ -96,8 +96,6 @@ int main(int argc, char **argv)
|
||||||
int timestamp = 0;
|
int timestamp = 0;
|
||||||
int datidx = 0;
|
int datidx = 0;
|
||||||
unsigned long fflen = 0;
|
unsigned long fflen = 0;
|
||||||
struct ifreq ifr;
|
|
||||||
int ifindex;
|
|
||||||
struct timeval tv, last_tv;
|
struct timeval tv, last_tv;
|
||||||
unsigned int n_pci;
|
unsigned int n_pci;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
@ -202,12 +200,8 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));
|
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, &rfilter, sizeof(rfilter));
|
||||||
|
|
||||||
strcpy(ifr.ifr_name, argv[optind]);
|
|
||||||
ioctl(s, SIOCGIFINDEX, &ifr);
|
|
||||||
ifindex = ifr.ifr_ifindex;
|
|
||||||
|
|
||||||
addr.can_family = AF_CAN;
|
addr.can_family = AF_CAN;
|
||||||
addr.can_ifindex = ifindex;
|
addr.can_ifindex = if_nametoindex(argv[optind]);
|
||||||
|
|
||||||
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
perror("bind");
|
perror("bind");
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int s;
|
int s;
|
||||||
struct sockaddr_can addr;
|
struct sockaddr_can addr;
|
||||||
struct ifreq ifr;
|
|
||||||
static struct can_isotp_options opts;
|
static struct can_isotp_options opts;
|
||||||
static struct can_isotp_fc_options fcopts;
|
static struct can_isotp_fc_options fcopts;
|
||||||
static struct can_isotp_ll_options llopts;
|
static struct can_isotp_ll_options llopts;
|
||||||
|
|
@ -232,9 +231,7 @@ int main(int argc, char **argv)
|
||||||
setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RX_STMIN, &force_rx_stmin, sizeof(force_rx_stmin));
|
setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_RX_STMIN, &force_rx_stmin, sizeof(force_rx_stmin));
|
||||||
|
|
||||||
addr.can_family = AF_CAN;
|
addr.can_family = AF_CAN;
|
||||||
strcpy(ifr.ifr_name, argv[optind]);
|
addr.can_ifindex = if_nametoindex(argv[optind]);
|
||||||
ioctl(s, SIOCGIFINDEX, &ifr);
|
|
||||||
addr.can_ifindex = ifr.ifr_ifindex;
|
|
||||||
|
|
||||||
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
perror("bind");
|
perror("bind");
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,6 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int s;
|
int s;
|
||||||
struct sockaddr_can addr;
|
struct sockaddr_can addr;
|
||||||
struct ifreq ifr;
|
|
||||||
static struct can_isotp_options opts;
|
static struct can_isotp_options opts;
|
||||||
static struct can_isotp_ll_options llopts;
|
static struct can_isotp_ll_options llopts;
|
||||||
int opt;
|
int opt;
|
||||||
|
|
@ -224,9 +223,7 @@ int main(int argc, char **argv)
|
||||||
setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_TX_STMIN, &force_tx_stmin, sizeof(force_tx_stmin));
|
setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_TX_STMIN, &force_tx_stmin, sizeof(force_tx_stmin));
|
||||||
|
|
||||||
addr.can_family = AF_CAN;
|
addr.can_family = AF_CAN;
|
||||||
strcpy(ifr.ifr_name, argv[optind]);
|
addr.can_ifindex = if_nametoindex(argv[optind]);
|
||||||
ioctl(s, SIOCGIFINDEX, &ifr);
|
|
||||||
addr.can_ifindex = ifr.ifr_ifindex;
|
|
||||||
|
|
||||||
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
perror("bind");
|
perror("bind");
|
||||||
|
|
|
||||||
|
|
@ -345,12 +345,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
caddr.can_family = AF_CAN;
|
caddr.can_family = AF_CAN;
|
||||||
strcpy(ifr.ifr_name, argv[optind]);
|
caddr.can_ifindex = if_nametoindex(argv[optind]);
|
||||||
if (ioctl(sc, SIOCGIFINDEX, &ifr) < 0) {
|
|
||||||
perror("SIOCGIFINDEX");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
caddr.can_ifindex = ifr.ifr_ifindex;
|
|
||||||
|
|
||||||
if (bind(sc, (struct sockaddr *)&caddr, caddrlen) < 0) {
|
if (bind(sc, (struct sockaddr *)&caddr, caddrlen) < 0) {
|
||||||
perror("bind");
|
perror("bind");
|
||||||
|
|
|
||||||
|
|
@ -271,9 +271,14 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
opts.flags |= CAN_ISOTP_LISTEN_MODE;
|
opts.flags |= CAN_ISOTP_LISTEN_MODE;
|
||||||
|
|
||||||
|
strncpy(ifr.ifr_name, argv[optind], IFNAMSIZ);
|
||||||
|
ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name);
|
||||||
|
if (!ifr.ifr_ifindex) {
|
||||||
|
perror("if_nametoindex");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
addr.can_family = AF_CAN;
|
addr.can_family = AF_CAN;
|
||||||
strcpy(ifr.ifr_name, argv[optind]);
|
|
||||||
ioctl(s, SIOCGIFINDEX, &ifr);
|
|
||||||
addr.can_ifindex = ifr.ifr_ifindex;
|
addr.can_ifindex = ifr.ifr_ifindex;
|
||||||
|
|
||||||
setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts));
|
setsockopt(s, SOL_CAN_ISOTP, CAN_ISOTP_OPTS, &opts, sizeof(opts));
|
||||||
|
|
|
||||||
10
isotptun.c
10
isotptun.c
|
|
@ -265,9 +265,15 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strncpy(ifr.ifr_name, argv[optind], IFNAMSIZ);
|
||||||
|
ifr.ifr_ifindex = if_nametoindex(ifr.ifr_name);
|
||||||
|
if (!ifr.ifr_ifindex) {
|
||||||
|
perror("if_nametoindex");
|
||||||
|
close(s);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
addr.can_family = AF_CAN;
|
addr.can_family = AF_CAN;
|
||||||
strcpy(ifr.ifr_name, argv[optind]);
|
|
||||||
ioctl(s, SIOCGIFINDEX, &ifr);
|
|
||||||
addr.can_ifindex = ifr.ifr_ifindex;
|
addr.can_ifindex = ifr.ifr_ifindex;
|
||||||
|
|
||||||
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
||||||
|
|
|
||||||
|
|
@ -415,7 +415,6 @@ int main(int argc, char **argv)
|
||||||
int s; /* can raw socket */
|
int s; /* can raw socket */
|
||||||
struct sockaddr_can addr;
|
struct sockaddr_can addr;
|
||||||
struct termios topts;
|
struct termios topts;
|
||||||
struct ifreq ifr;
|
|
||||||
int select_stdin = 0;
|
int select_stdin = 0;
|
||||||
int running = 1;
|
int running = 1;
|
||||||
int tstamp = 0;
|
int tstamp = 0;
|
||||||
|
|
@ -490,13 +489,7 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
addr.can_family = AF_CAN;
|
addr.can_family = AF_CAN;
|
||||||
|
addr.can_ifindex = if_nametoindex(argv[2]);
|
||||||
strcpy(ifr.ifr_name, argv[2]);
|
|
||||||
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
|
|
||||||
perror("SIOCGIFINDEX");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
addr.can_ifindex = ifr.ifr_ifindex;
|
|
||||||
|
|
||||||
/* disable reception of CAN frames until we are opened by 'O' */
|
/* disable reception of CAN frames until we are opened by 'O' */
|
||||||
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
|
setsockopt(s, SOL_CAN_RAW, CAN_RAW_FILTER, NULL, 0);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue