[PATCH] wifi: mt76: Fix strscpy usage in mt76_connac2_load_patch

Ivan Orlov ivan.orlov0322 at gmail.com
Sat Dec 27 04:25:24 PST 2025


Since mt76_connac2_patch_hdr->build_date size is 16, copying at most 17
bytes into build_date from it causes a panic when CONFIG_FORTIFY_SOURCE
is enabled. So, make it 16 bytes instead to match the corresponding
field of mt76_connac2_patch_hdr.

Also, since strscpy always adds a null terminator, remove the line which
adds it explicitly at the end of the buffer.

Signed-off-by: Ivan Orlov <ivan.orlov0322 at gmail.com>
---
 drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
index ea99167765b0..01362b097a40 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76_connac_mcu.c
@@ -3101,7 +3101,7 @@ int mt76_connac2_load_patch(struct mt76_dev *dev, const char *fw_name)
 	int i, ret, sem, max_len = mt76_is_sdio(dev) ? 2048 : 4096;
 	const struct mt76_connac2_patch_hdr *hdr;
 	const struct firmware *fw = NULL;
-	char build_date[17];
+	char build_date[16];
 
 	sem = mt76_connac_mcu_patch_sem_ctrl(dev, true);
 	switch (sem) {
@@ -3126,7 +3126,6 @@ int mt76_connac2_load_patch(struct mt76_dev *dev, const char *fw_name)
 
 	hdr = (const void *)fw->data;
 	strscpy(build_date, hdr->build_date, sizeof(build_date));
-	build_date[16] = '\0';
 	strim(build_date);
 	dev_info(dev->dev, "HW/SW Version: 0x%x, Build Time: %.16s\n",
 		 be32_to_cpu(hdr->hw_sw_ver), build_date);
-- 
2.43.0




More information about the Linux-mediatek mailing list