staging: wlan-ng: fix uninitialized variable
Subsystems (2)
PATCH 1/1 staging: wlan-ng: fix uninitialized variable
The result variable in prism2_connect() can be used uninitialized on path !channel --> ... --> is_wep --> sme->key --> sme->key_idx >= NUM_WEPKEYS. This patch initializes result with 0.
--- drivers/staging/wlan-ng/cfg80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wlan-ng/cfg80211.c +1 -1
@@ -441,7 +441,7 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,int chan =-1 ;int is_wep = (sme->crypto.cipher_group ==WLAN_CIPHER_SUITE_WEP40 ) || (sme->crypto.cipher_group ==WLAN_CIPHER_SUITE_WEP104 ); -int result; +int result =0 ;int err =0 ;/* Set the channel */
Signature · 1 line
2.21.0
Quoted 16 lines · Denis Efremov
The result variable in
prism2_connect()can be used uninitialized on path !channel --> ... -->is_wep-->sme->key-->sme->key_idx>=NUM_WEPKEYS. This patch initializes result with 0.Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Denis Efremov <[email protected]>--- drivers/staging/wlan-ng/cfg80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/wlan-ng/cfg80211.c +0
-0
drivers/staging/wlan-ng/cfg80211.c static int prism2_connect(struct wiphy *wiphy, struct net_device *dev, · line 446
Quoted 7 lines
drivers/staging/wlan-ng/cfg80211.c +1
-1@@ -441,7 +441,7 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,int chan =-1 ;int is_wep = (sme->crypto.cipher_group ==WLAN_CIPHER_SUITE_WEP40 ) || (sme->crypto.cipher_group ==WLAN_CIPHER_SUITE_WEP104 ); -int result; +int result =0 ;int err =0 ;
I can't see any reason why we should have both "err" and "result". Maybe in olden times "result" used to save positive error codes instead of negative error codes but now it's just negatives and zero on success. There is no reason for the exit label either, we could just return directly.
So could you redo it and get rid of "result" entirely? Otherwise it just causes more bugs like this.
regards,
dan carpenter
Hi,
Quoted 31 lines · Dan Carpenter
Quoted 16 lines · Denis Efremov
The result variable in
prism2_connect()can be used uninitialized on path !channel --> ... -->is_wep-->sme->key-->sme->key_idx>=NUM_WEPKEYS. This patch initializes result with 0.Cc Greg Kroah-Hartman <[email protected]>Signed-off-by Denis Efremov <[email protected]>--- drivers/staging/wlan-ng/cfg80211.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/wlan-ng/cfg80211.c +0
-0drivers/staging/wlan-ng/cfg80211.c static int prism2_connect(struct wiphy *wiphy, struct net_device *dev, · line 446
Quoted 7 lines
drivers/staging/wlan-ng/cfg80211.c +1
-1@@ -441,7 +441,7 @@ static int prism2_connect(struct wiphy *wiphy, struct net_device *dev,int chan =-1 ;int is_wep = (sme->crypto.cipher_group ==WLAN_CIPHER_SUITE_WEP40 ) || (sme->crypto.cipher_group ==WLAN_CIPHER_SUITE_WEP104 ); -int result; +int result =0 ;int err =0 ;I can't see any reason why we should have both "err" and "result". Maybe in olden times "result" used to save positive error codes instead of negative error codes but now it's just negatives and zero on success. There is no reason for the exit label either, we could just return directly.
Quoted 3 lines
So could you redo it and get rid of "result" entirely? Otherwise it just causes more bugs like this.
Yes, of course. I will prepare v2.
Thanks,
Denis