linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] staging: rtl8188eu: fix potential leak in update_bcn_wps_ie()
@ 2014-05-07 19:42 Christian Engelmayer
  2014-05-08  5:16 ` Jes Sorensen
  0 siblings, 1 reply; 2+ messages in thread
From: Christian Engelmayer @ 2014-05-07 19:42 UTC (permalink / raw)
  To: devel; +Cc: gregkh, Jes.Sorensen, mguzik, linux-kernel, Larry.Finger

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>
---
v3: Resend after v2 failed to apply

  * rebased against staging-next - commit 09c3fbba (staging: rtl8188eu:
    Remove 'u8 *pbuf' from struct recv_buf)
  * fixed mua: no multipart, 7bit text/plain us-ascii

v2: Added change suggested by Mateusz Guzik for the rtl8723au variant:

    Move the check before allocating the memory instead of freeing the
    resource afterwards in the error path.

Compile tested and applies against branch staging-next of tree
git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
---
 drivers/staging/rtl8188eu/core/rtw_ap.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/rtl8188eu/core/rtw_ap.c b/drivers/staging/rtl8188eu/core/rtw_ap.c
index ff74d0d..85fda61 100644
--- a/drivers/staging/rtl8188eu/core/rtw_ap.c
+++ b/drivers/staging/rtl8188eu/core/rtw_ap.c
@@ -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);
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] staging: rtl8188eu: fix potential leak in update_bcn_wps_ie()
  2014-05-07 19:42 [PATCH v3] staging: rtl8188eu: fix potential leak in update_bcn_wps_ie() Christian Engelmayer
@ 2014-05-08  5:16 ` Jes Sorensen
  0 siblings, 0 replies; 2+ messages in thread
From: Jes Sorensen @ 2014-05-08  5:16 UTC (permalink / raw)
  To: Christian Engelmayer; +Cc: devel, gregkh, mguzik, linux-kernel, Larry.Finger

Christian Engelmayer <cengelma@gmx.at> writes:
> 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>
> ---
> v3: Resend after v2 failed to apply
>
>   * rebased against staging-next - commit 09c3fbba (staging: rtl8188eu:
>     Remove 'u8 *pbuf' from struct recv_buf)
>   * fixed mua: no multipart, 7bit text/plain us-ascii
>
> v2: Added change suggested by Mateusz Guzik for the rtl8723au variant:
>
>     Move the check before allocating the memory instead of freeing the
>     resource afterwards in the error path.
>
> Compile tested and applies against branch staging-next of tree
> git.kernel.org/pub/scm/linux/kernel/git/gregkh/staging.git
> ---
>  drivers/staging/rtl8188eu/core/rtw_ap.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)

Acked-by: Jes Sorensen <Jes.Sorensen@redhat.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-08  5:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-07 19:42 [PATCH v3] staging: rtl8188eu: fix potential leak in update_bcn_wps_ie() Christian Engelmayer
2014-05-08  5:16 ` Jes Sorensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).