Skip to content

Commit

Permalink
Correct the use of snprintf in owinterface_add
Browse files Browse the repository at this point in the history
The origin size value of snprintf in owinterface_add was ETH_ALEN, if
the string size is too large, it will only allow ETH_ALEN - 1 characters
to be copied into the buffer.

However, the buffer starts from location inf_name + 1 and the last
character must be '\0', which means that the buffer only has at most
ETH_ALEN - 2 characters space left.

So the size value in snprintf of owinterface_add should be ETH_ALEN - 1
  • Loading branch information
vax-r committed Dec 1, 2023
1 parent 3db379f commit e5eb949
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion vwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,7 @@ static struct wireless_dev *owinterface_add(struct wiphy *wiphy, int if_idx)
* address (the first byte of multicast addrs is odd).
*/
char intf_name[ETH_ALEN] = {0};
snprintf(intf_name + 1, ETH_ALEN, "%s%d", NAME_PREFIX, if_idx);
snprintf(intf_name + 1, ETH_ALEN - 1, "%s%d", NAME_PREFIX, if_idx);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)
eth_hw_addr_set(vif->ndev, intf_name);
Expand Down

0 comments on commit e5eb949

Please sign in to comment.