Skip to contentSkip to conversation

igb: Add null pointer check to igb_set_fw_version

PATCH In review Kunwu Chan 2 participants 3 messages Dec 11, 2023 – Dec 14, 2023

Subsystems (3)
lore
Share & tools
lore

Kunwu Chan

author
#0 lore raw

PATCH 1/1 igb: Add null pointer check to igb_set_fw_version

kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure.

Fixes 1978d3ead82c ("intel: fix string truncation warnings")
Cc Kunwu Chan <[email protected]>
---
 drivers/net/ethernet/intel/igb/igb_main.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/ethernet/intel/igb/igb_main.c +2 -0
index b2295caa2f0a..6838f6fccb80 100644
@@ -3102,6 +3102,8 @@ void igb_set_fw_version(struct igb_adapter *adapter)
 		break;
 	}
 
+	if (!lbuf)
+		return;
 	/* the truncate happens here if it doesn't fit */
 	strscpy(adapter->fw_version, lbuf, sizeof(adapter->fw_version));
 	kfree(lbuf);
Signature · 1 line
2.39.2
maintainer
#1 lore raw
Quoted 6 lines · On Mon, 11 Dec 2023 11:13:36 +0800 Kunwu Chan wrote:

kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure.

Fixes 1978d3ead82c ("intel: fix string truncation warnings")
Cc Kunwu Chan <[email protected]>

The allocation is rather pointless here.
Can you convert this code to use snprintf() instead?

Signature · 1 line
pw-bot: cr
author
#2 lore raw

Thanks for your reply.

I'll try to use snprintf in v2 patch.

Quoted 10 lines · Jakub Kicinski
Quoted 6 lines · On Mon, 11 Dec 2023 11:13:36 +0800 Kunwu Chan wrote:

kasprintf() returns a pointer to dynamically allocated memory which can be NULL upon failure.

Fixes 1978d3ead82c ("intel: fix string truncation warnings")
Cc Kunwu Chan <[email protected]>

The allocation is rather pointless here.
Can you convert this code to use snprintf() instead?