Skip to content

Commit b5823dc

Browse files
Wang Xinmarckleinebudde
authored andcommitted
Fix attribute list size in do_get_nl_link()
The function do_get_nl_link() retrieves attributes from the response RTM_NEWLINK. But it calculates the attribute list size with the wrong structure struct ifaddrmsg. According to man 7 rtnetlink, RTM_NEWLINK message uses struct ifinfomsg instead of struct ifaddrmsg. This causes that additional 8 bytes are parsed and garbage attributes might be retrieved. One of consequences is that the message will be dropped if the garbage attribute is IFLA_IFNAME and contains an invalid interface name. To fix this issue, use struct ifinfomsg to calculate the size of attribute list for RTM_NEWLINK. Signed-off-by: Wang Xin <xin.wang7@cn.bosch.com> Signed-off-by: Mark Jonas <mark.jonas@de.bosch.com> Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
1 parent df01f01 commit b5823dc

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/libsocketcan.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ static int do_get_nl_link(int fd, __u8 acquire, const char *name, void *res)
411411
struct rtattr *tb[IFLA_MAX + 1];
412412

413413
len =
414-
nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifaddrmsg));
414+
nl_msg->nlmsg_len - NLMSG_LENGTH(sizeof(struct ifinfomsg));
415415
parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
416416

417417
/* Finish process if the reply message is matched */

0 commit comments

Comments
 (0)