Thread (2 messages) flat view 2 messages, 2 authors, 2015-07-27
STALE4073d

[PATCH] android/hal-bluetooth: Fix NULL ptr dereference

From: Atul Rai <hidden>
Date: 2015-06-29 06:44:13
Subsystem: the rest · Maintainer: Linus Torvalds

Add NULL check on malloc return to fix NULL pointer dereference
in case malloc fails.
---
 android/hal-bluetooth.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index e24f7d2..66f4a37 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 #include <string.h>
+#include <errno.h>
 
 #include <cutils/properties.h>
 
@@ -1103,6 +1104,11 @@ static int open_bluetooth(const struct hw_module_t *module, char const *name,
 
 	DBG("");
 
+	if (!dev) {
+		error("Failed to allocate memory for device");
+		return -ENOMEM;
+	}
+
 	memset(dev, 0, sizeof(bluetooth_device_t));
 	dev->common.tag = HARDWARE_DEVICE_TAG;
 	dev->common.version = 0;
-- 
2.1.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help