[PATCH 2/5] staging: ks7010: move null check before dereference

Tobin C. Harding me at tobin.cc
Sun Mar 26 10:03:20 UTC 2017


Pointer is dereferenced before the null check. Pointer variable is set
(using a cast) to point to a function argument, the pointer is then
dereferenced before it is checked for non-null.

Move null check to before the dereference.

Signed-off-by: Tobin C. Harding <me at tobin.cc>
---
 drivers/staging/ks7010/ks_wlan_net.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/ks7010/ks_wlan_net.c b/drivers/staging/ks7010/ks_wlan_net.c
index dc89c16..b467307 100644
--- a/drivers/staging/ks7010/ks_wlan_net.c
+++ b/drivers/staging/ks7010/ks_wlan_net.c
@@ -1771,6 +1771,8 @@ static int ks_wlan_set_encode_ext(struct net_device *dev,
 	unsigned int commit = 0;
 
 	enc = (struct iw_encode_ext *)extra;
+	if (!enc)
+		return -EINVAL;
 
 	DPRINTK(2, "flags=%04X:: ext_flags=%08X\n", dwrq->flags,
 		enc->ext_flags);
@@ -1786,9 +1788,6 @@ static int ks_wlan_set_encode_ext(struct net_device *dev,
 	if (dwrq->flags & IW_ENCODE_DISABLED)
 		priv->wpa.key[index].key_len = 0;
 
-	if (!enc)
-		return -EINVAL;
-
 	priv->wpa.key[index].ext_flags = enc->ext_flags;
 	if (enc->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
 		priv->wpa.txkey = index;
-- 
2.7.4



More information about the devel mailing list