From nobody@FreeBSD.org  Fri Dec 30 22:09:04 2011
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 76CA51065673
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Dec 2011 22:09:04 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 6606C8FC0A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Dec 2011 22:09:04 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id pBUM94Kx026243
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 30 Dec 2011 22:09:04 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id pBUM946P026242;
	Fri, 30 Dec 2011 22:09:04 GMT
	(envelope-from nobody)
Message-Id: <201112302209.pBUM946P026242@red.freebsd.org>
Date: Fri, 30 Dec 2011 22:09:04 GMT
From: Philippe Saint-Pierre <stpere@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [PATCH] NULL check before dereference
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         163724
>Category:       kern
>Synopsis:       [mwl] [patch] NULL check before dereference
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-wireless
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Dec 30 22:10:12 UTC 2011
>Closed-Date:    
>Last-Modified:  Fri Dec 30 22:14:40 UTC 2011
>Originator:     Philippe Saint-Pierre
>Release:        patch made against 8.1 (I think)
>Organization:
Haiku
>Environment:
>Description:
In the Marvell wifi driver, there are dereferences attempts occuring before the NULL check.
>How-To-Repeat:

>Fix:
Patch included.  Basically moves the NULL check to before any dereferences attempts.

Patch attached with submission follows:

--- mwlhal-orig.c	2011-12-30 12:49:08.807786944 -0500
+++ sys/dev/mwl/mwlhal.c	2011-12-30 12:50:57.787782085 -0500
@@ -1440,15 +1440,20 @@
 	}
 	sp = &mh->mh_streams[s];
 	mh->mh_bastreams &= ~(1<<s);
-	sp->public.data[0] = a1;
-	sp->public.data[1] = a2;
-	IEEE80211_ADDR_COPY(sp->macaddr, Macaddr);
-	sp->tid = Tid;
-	sp->paraminfo = ParamInfo;
-	sp->setup = 0;
-	sp->ba_policy = ba_policy;
-	MWL_HAL_UNLOCK(mh);
-	return sp != NULL ? &sp->public : NULL;
+	if (sp != NULL) {
+		sp->public.data[0] = a1;
+		sp->public.data[1] = a2;
+		IEEE80211_ADDR_COPY(sp->macaddr, Macaddr);
+		sp->tid = Tid;
+		sp->paraminfo = ParamInfo;
+		sp->setup = 0;
+		sp->ba_policy = ba_policy;
+		MWL_HAL_UNLOCK(mh);
+		return &sp->public;
+	} else {
+		MWL_HAL_UNLOCK(mh);
+		return NULL;
+	}
 }
 
 const MWL_HAL_BASTREAM *


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-wireless 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Fri Dec 30 22:14:19 UTC 2011 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=163724 
>Unformatted:
