igb: Add null pointer check to igb_set_fw_version
Subsystems (3)
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]>
Signed-off-by 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
@@ -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
Jakub Kicinski
maintainerQuoted 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]>Signed-off-by 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
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]>Signed-off-by Kunwu Chan <[email protected]>The allocation is rather pointless here.
Can you convert this code to usesnprintf()instead?