Skip to contentSkip to conversation

emulator/bthost: Fix use after free in bthost_destroy

PATCH Applied Szymon Janc 2 participants 2 messages Dec 15, 2013 – Dec 16, 2013 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 emulator/bthost: Fix use after free in bthost_destroy

cmd was dereferenced after free. Use temp pointer for freeing.

---
 emulator/bthost.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
emulator/bthost.c +5 -3
index 10e7a05..b05072a 100644
@@ -186,13 +186,15 @@ static struct l2conn *btconn_find_l2cap_conn_by_scid(struct btconn *conn,
 
 void bthost_destroy(struct bthost *bthost)
 {
-	struct cmd *cmd;
-
 	if (!bthost)
 		return;
 
-	for (cmd = bthost->cmd_q.tail; cmd != NULL; cmd = cmd->next)
+	while (bthost->cmd_q.tail) {
+		struct cmd *cmd = bthost->cmd_q.tail;
+
+		bthost->cmd_q.tail = cmd->next;
 		free(cmd);
+	}
 
 	while (bthost->conns) {
 		struct btconn *conn = bthost->conns;
Signature · 1 line
1.8.5.1
#1 lore raw

Hi Szymon,

Quoted 4 lines · Szymon Janc

cmd was dereferenced after free. Use temp pointer for freeing.

---
 emulator/bthost.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Applied. Thanks.

Johan