Blame SOURCES/0001-gatt-Fix-double-free-and-freed-memory-dereference.patch

150e62
From f853012bc0142ab6056f3d9ef4abf621b1e8a756 Mon Sep 17 00:00:00 2001
150e62
From: Gopal Tiwari <gtiwari@redhat.com>
150e62
Date: Tue, 24 May 2022 16:45:56 +0530
150e62
Subject: [PATCH BlueZ] gatt: Fix double free and freed memory dereference
150e62
150e62
commit 3627eddea13042ffc0848ae37356f30335ce2e4b
150e62
Author: Ildar Kamaletdinov <i.kamaletdinov@omp.ru>
150e62
Date:   Fri Apr 1 15:16:47 2022 +0300
150e62
150e62
    gatt: Fix double free and freed memory dereference
150e62
150e62
    If device is no longer exists or not paired when notifications send it
150e62
    is possible to get double free and dereference of already freed memory.
150e62
150e62
    To avoid this we need to recheck the state of device after sending
150e62
    notification.
150e62
150e62
    Found by Linux Verification Center (linuxtesting.org) with the SVACE
150e62
    static analysis tool.
150e62
---
150e62
 src/gatt-database.c | 4 ++++
150e62
 1 file changed, 4 insertions(+)
150e62
150e62
diff --git a/src/gatt-database.c b/src/gatt-database.c
150e62
index d6c94058c..d32f616a9 100644
150e62
--- a/src/gatt-database.c
150e62
+++ b/src/gatt-database.c
150e62
@@ -3877,6 +3877,10 @@ void btd_gatt_database_server_connected(struct btd_gatt_database *database,
150e62
 
150e62
 	send_notification_to_device(state, state->pending);
150e62
 
150e62
+	state = find_device_state(database, &bdaddr, bdaddr_type);
150e62
+	if (!state || !state->pending)
150e62
+		return;
150e62
+
150e62
 	free(state->pending->value);
150e62
 	free(state->pending);
150e62
 	state->pending = NULL;
150e62
-- 
150e62
2.26.2
150e62