All of lore.kernel.org
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@codecoup.pl>
To: linux-bluetooth@vger.kernel.org
Cc: Szymon Janc <szymon.janc@codecoup.pl>
Subject: [PATCH] input/hog: Fix crash if uhid is not enabled
Date: Fri,  1 Apr 2016 21:58:29 +0200	[thread overview]
Message-ID: <1459540709-2058-1-git-send-email-szymon.janc@codecoup.pl> (raw)

If /dev/uhid is not present bt_hog_new_default() returns NULL.
This was resulting in NULL pointer dereference in attio_connected_cb.
---
 profiles/input/hog.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/profiles/input/hog.c b/profiles/input/hog.c
index 4dba83f..a934c62 100644
--- a/profiles/input/hog.c
+++ b/profiles/input/hog.c
@@ -107,8 +107,13 @@ static struct hog_device *hog_device_new(struct btd_device *device,
 							product, version);
 
 	dev = new0(struct hog_device, 1);
-	dev->device = btd_device_ref(device);
 	dev->hog = bt_hog_new_default(name, vendor, product, version, prim);
+	if (!dev->hog) {
+		free(dev);
+		return NULL;
+	}
+
+	dev->device = btd_device_ref(device);
 
 	/*
 	 * TODO: Remove attio callback and use .accept once using
@@ -189,6 +194,9 @@ static int hog_probe(struct btd_service *service)
 			continue;
 
 		dev = hog_device_new(device, prim);
+		if (!dev)
+			break;
+
 		btd_service_set_user_data(service, dev);
 		return 0;
 	}
-- 
2.6.2


             reply	other threads:[~2016-04-01 19:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-01 19:58 Szymon Janc [this message]
2016-04-02  7:48 ` [PATCH] input/hog: Fix crash if uhid is not enabled Johan Hedberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1459540709-2058-1-git-send-email-szymon.janc@codecoup.pl \
    --to=szymon.janc@codecoup.pl \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.