staging: rtl8188eu: fix potential leak in update_bcn_wps_ie()
authorChristian Engelmayer <cengelma@gmx.at>
Wed, 7 May 2014 19:42:27 +0000 (21:42 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 23 May 2014 16:45:49 +0000 (01:45 +0900)
Fix a potential leak in the error path of function update_bcn_wps_ie().
Move the affected input verification to the beginning of the function so
that it may return directly without leaking already allocated memory.
Detected by Coverity - CID 1077718.

Signed-off-by: Christian Engelmayer <cengelma@gmx.at>
Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/rtl8188eu/core/rtw_ap.c

index ff74d0d7efa30674e6c592a2dffbb3a870f0ed2e..85fda6128db9ccc472acce94c3f966c6f204d090 100644 (file)
@@ -1306,6 +1306,10 @@ static void update_bcn_wps_ie(struct adapter *padapter)
 
        DBG_88E("%s\n", __func__);
 
+       pwps_ie_src = pmlmepriv->wps_beacon_ie;
+       if (pwps_ie_src == NULL)
+               return;
+
        pwps_ie = rtw_get_wps_ie(ie+_FIXED_IE_LENGTH_, ielen-_FIXED_IE_LENGTH_, NULL, &wps_ielen);
 
        if (pwps_ie == NULL || wps_ielen == 0)
@@ -1323,10 +1327,6 @@ static void update_bcn_wps_ie(struct adapter *padapter)
                        memcpy(pbackup_remainder_ie, premainder_ie, remainder_ielen);
        }
 
-       pwps_ie_src = pmlmepriv->wps_beacon_ie;
-       if (pwps_ie_src == NULL)
-               return;
-
        wps_ielen = (uint)pwps_ie_src[1];/* to get ie data len */
        if ((wps_offset+wps_ielen+2+remainder_ielen) <= MAX_IE_SZ) {
                memcpy(pwps_ie, pwps_ie_src, wps_ielen+2);