Skip to contentSkip to conversation

Fix possible NULL pointer deference

PATCH In review Luiz Augusto von Dentz 2 participants 8 messages Oct 12, 2010 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/4 Fix possible NULL pointer deference

From: Luiz Augusto von Dentz <[email protected]>

Variable "os->driver" tracked as NULL.

---
 src/obex.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
src/obex.c +3 -1
index 92d3b5c..8d12f8f 100644
@@ -589,7 +589,9 @@ static int obex_read_stream(struct obex_session *os, obex_t *obex,
 	os->buf = g_realloc(os->buf, os->pending + size);
 	memcpy(os->buf + os->pending, buffer, size);
 	os->pending += size;
-	if (os->object == NULL) {
+
+	/* only write if both object and driver are valid */
+	if (os->object == NULL || os->driver == NULL) {
 		DBG("Stored %u bytes into temporary buffer", os->pending);
 		return 0;
 	}
Signature · 1 line
1.7.1
author maintainer
#1 lore raw

PATCH 2/4 Fix possible NULL pointer deference

From: Luiz Augusto von Dentz <[email protected]>

Variable "transfer" tracked as NULL was passed to function "transfer_unregister" that dereferences it.

---
 client/session.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
client/session.c +2 -4
index 7539a97..ce3432d 100644
@@ -1274,10 +1274,8 @@ int session_send(struct session_data *session, const char *filename,
 
 	transfer = transfer_register(session, filename, targetname, NULL,
 					NULL);
-	if (transfer == NULL) {
-		err = -EINVAL;
-		goto fail;
-	}
+	if (transfer == NULL)
+		return -EINVAL;
 
 	/* Transfer should start if it is the first in the pending list */
 	if (transfer != session->pending->data)
Signature · 1 line
1.7.1
#2 lore raw

Hi Luiz,

Quoted 7 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Variable "transfer" tracked as NULL was passed to function "transfer_unregister" that dereferences it.

---
 client/session.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

Pushed upstream. Thanks.

Johan

author maintainer
#3 lore raw

PATCH 3/4 Fix dead statement

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Cannot reach dead statement "(*os->driver->close)(object);"

---
 src/obex.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)
src/obex.c +1 -7
index 8d12f8f..41ba558 100644
@@ -882,7 +882,7 @@ int obex_get_stream_start(struct obex_session *os, const char *filename)
 								&size, &err);
 	if (object == NULL) {
 		error("open(%s): %s (%d)", filename, strerror(-err), -err);
-		goto fail;
+		return err;
 	}
 
 	os->object = object;
@@ -893,12 +893,6 @@ int obex_get_stream_start(struct obex_session *os, const char *filename)
 		os->buf = g_malloc0(os->tx_mtu);
 
 	return 0;
-
-fail:
-	if (object)
-		os->driver->close(object);
-
-	return err;
 }
 
 int obex_put_stream_start(struct obex_session *os, const char *filename)
Signature · 1 line
1.7.1
#4 lore raw

Re: [PATCH 3/4] Fix dead statement

Hi Luiz,

Quoted 6 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Cannot reach dead statement "(*os->driver->close)(object);"

---
 src/obex.c |    8 +-------
 1 files changed, 1 insertions(+), 7 deletions(-)

This one is also upstream.

Johan

author maintainer
#5 lore raw

PATCH 4/4 Fix possible use of uninitialized variables

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Using uninitialized value "hi" and "flags" in call to function "OBEX_ObjectAddHeader".

---
 src/obex.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
src/obex.c +3 -0
index 41ba558..3e9f5b6 100644
@@ -670,6 +670,9 @@ add_header:
 	case OBEX_HDR_APPARAM:
 		flags =  0;
 		break;
+	default:
+		error("read(): unkown header type %u", hi);
+		return -EIO;
 	}
 
 	OBEX_ObjectAddHeader(obex, obj, hi, hd, len, flags);
Signature · 1 line
1.7.1
#6 lore raw

Re: [PATCH 4/4] Fix possible use of uninitialized variables

Hi Luiz,

Quoted 7 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Using uninitialized value "hi" and "flags" in call to function "OBEX_ObjectAddHeader".

---
 src/obex.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

And this one has also been pushed upstream. Thanks.

Johan