[PATCH 1/2] shared/gatt: Fix dereference before NULL check warnings

Subsystems: the rest

STALE4330d

4 messages, 2 authors, 2014-11-27 · open the first message on its own page

[PATCH 1/2] shared/gatt: Fix dereference before NULL check warnings

From: Andrei Emeltchenko <hidden>
Date: 2014-11-20 13:13:14

From: Andrei Emeltchenko <redacted>

Add NULL check otherwise constructions like below give warnings:
...
	uint8_t pdu[4 + get_uuid_len(uuid)];

	if (!att || !uuid || uuid->type == BT_UUID_UNSPEC)
...
---
 src/shared/gatt-helpers.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index d0bee3f..dc4a8e8 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -588,6 +588,9 @@ static void put_uuid_le(const bt_uuid_t *src, void *dst)
 
 static inline int get_uuid_len(const bt_uuid_t *uuid)
 {
+	if (!uuid)
+		return 0;
+
 	return (uuid->type == BT_UUID16) ? 2 : 16;
 }
 
-- 
1.9.1

[PATCH 2/2] tools/gatt: Fix memory leak

From: Andrei Emeltchenko <hidden>
Date: 2014-11-20 13:13:15

From: Andrei Emeltchenko <redacted>

Fixes following clang warning:
...
tools/btgatt-client.c:451:4: warning: Potential leak of memory pointed
to by 'value'
                        printf("Invalid value byte: %s\n", argv[i]);
                        ^~~~~~
...
---
 tools/btgatt-client.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index ca84780..dadfa37 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -449,6 +449,7 @@ static void cmd_read_multiple(struct client *cli, char *cmd_str)
 		value[i] = strtol(argv[i], &endptr, 0);
 		if (endptr == argv[i] || *endptr != '\0' || !value[i]) {
 			printf("Invalid value byte: %s\n", argv[i]);
+			free(value);
 			return;
 		}
 	}
-- 
1.9.1

Re: [PATCH 1/2] shared/gatt: Fix dereference before NULL check warnings

From: Andrei Emeltchenko <hidden>
Date: 2014-11-27 09:04:31

ping

On Thu, Nov 20, 2014 at 03:13:14PM +0200, Andrei Emeltchenko wrote:
quoted hunk
From: Andrei Emeltchenko <redacted>

Add NULL check otherwise constructions like below give warnings:
...
	uint8_t pdu[4 + get_uuid_len(uuid)];

	if (!att || !uuid || uuid->type == BT_UUID_UNSPEC)
...
---
 src/shared/gatt-helpers.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/src/shared/gatt-helpers.c b/src/shared/gatt-helpers.c
index d0bee3f..dc4a8e8 100644
--- a/src/shared/gatt-helpers.c
+++ b/src/shared/gatt-helpers.c
@@ -588,6 +588,9 @@ static void put_uuid_le(const bt_uuid_t *src, void *dst)
 
 static inline int get_uuid_len(const bt_uuid_t *uuid)
 {
+	if (!uuid)
+		return 0;
+
 	return (uuid->type == BT_UUID16) ? 2 : 16;
 }
 
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Re: [PATCH 1/2] shared/gatt: Fix dereference before NULL check warnings

From: Johan Hedberg <hidden>
Date: 2014-11-27 12:58:23

Hi Andrei,

On Thu, Nov 20, 2014, Andrei Emeltchenko wrote:
Add NULL check otherwise constructions like below give warnings:
...
	uint8_t pdu[4 + get_uuid_len(uuid)];

	if (!att || !uuid || uuid->type == BT_UUID_UNSPEC)
...
---
 src/shared/gatt-helpers.c | 3 +++
 1 file changed, 3 insertions(+)
Both patches in this set have been applied. Thanks.

Johan
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help