From e5eb9496665c7d8c68f5c42c22546ddffc90b997 Mon Sep 17 00:00:00 2001 From: vax-r Date: Wed, 29 Nov 2023 20:23:52 +0800 Subject: [PATCH] Correct the use of snprintf in owinterface_add 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 --- vwifi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vwifi.c b/vwifi.c index de7424f..f3ffbfd 100644 --- a/vwifi.c +++ b/vwifi.c @@ -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);