Skip to contentSkip to conversation

staging: wlan-ng: fix uninitialized variable

PATCH In review Denis Efremov 2 participants 3 messages Oct 2, 2019 – Oct 3, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index eee1998c4b18..d426905e187e 100644
@@ -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
#1 lore raw
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.

---
 drivers/staging/wlan-ng/cfg80211.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wlan-ng/cfg80211.c +0 -0
index eee1998c4b18..d426905e187e 100644

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

#2 lore raw

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.

---
 drivers/staging/wlan-ng/cfg80211.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/wlan-ng/cfg80211.c +0 -0
index eee1998c4b18..d426905e187e 100644

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.

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