Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: mgmt: Fix dereference after NULL check
@ 2012-10-04 10:56 Andrei Emeltchenko
  2012-10-04 12:17 ` Johan Hedberg
  0 siblings, 1 reply; 3+ messages in thread
From: Andrei Emeltchenko @ 2012-10-04 10:56 UTC (permalink / raw)
  To: linux-bluetooth

From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>

hdev might be NULL, so we need to avoid possible NULL derefernce in
handler->func functions.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
 net/bluetooth/mgmt.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index b127b88..be3182c 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -2738,7 +2738,6 @@ static const struct mgmt_handler {
 int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
 {
 	void *buf;
-	u8 *cp;
 	struct mgmt_hdr *hdr;
 	u16 opcode, index, len;
 	struct hci_dev *hdev = NULL;
@@ -2802,14 +2801,17 @@ int mgmt_control(struct sock *sk, struct msghdr *msg, size_t msglen)
 		goto done;
 	}
 
-	if (hdev)
+	if (hdev) {
+		u8 *cp;
+
 		mgmt_init_hdev(sk, hdev);
 
-	cp = buf + sizeof(*hdr);
+		cp = buf + sizeof(*hdr);
 
-	err = handler->func(sk, hdev, cp, len);
-	if (err < 0)
-		goto done;
+		err = handler->func(sk, hdev, cp, len);
+		if (err < 0)
+			goto done;
+	}
 
 	err = msglen;
 
-- 
1.7.9.5


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

end of thread, other threads:[~2012-10-04 12:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-04 10:56 [PATCH] Bluetooth: mgmt: Fix dereference after NULL check Andrei Emeltchenko
2012-10-04 12:17 ` Johan Hedberg
2012-10-04 12:33   ` Andrei Emeltchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox