diff mbox series

[BlueZ,7/7] gatt: Fix double free and freed memory dereference

Message ID 20220401074640.3956695-8-i.kamaletdinov@omp.ru (mailing list archive)
State Superseded
Headers show
Series Fix bugs found by SVACE static analisys tool | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/checkpatch warning [BlueZ,7/7] gatt: Fix double free and freed memory dereference WARNING:TYPO_SPELLING: 'occure' may be misspelled - perhaps 'occurred'? #50: notification it is possible to to occure double free and dereference of ^^^^^^ WARNING:REPEATED_WORD: Possible repeated word: 'to' #50: notification it is possible to to occure double free and dereference of /github/workspace/src/12797968.patch total: 0 errors, 2 warnings, 10 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/12797968.patch has style problems, please review. NOTE: Ignored message types: COMMIT_MESSAGE COMPLEX_MACRO CONST_STRUCT FILE_PATH_CHANGES MISSING_SIGN_OFF PREFER_PACKED SPDX_LICENSE_TAG SPLIT_STRING SSCANF_TO_KSTRTO NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/gitlint success Gitlint PASS

Commit Message

Ildar Kamaletdinov April 1, 2022, 7:46 a.m. UTC
In condition where device no longer exist or not paired when sending
notification it is possible to to occure double free and dereference of
already freed memory.

To avoid this we need to recheck the state of device after sending
notification.

Found by Linux Verification Center (linuxtesting.org) with the SVACE
static analysis tool.
---
 src/gatt-database.c | 4 ++++
 1 file changed, 4 insertions(+)
diff mbox series

Patch

diff --git a/src/gatt-database.c b/src/gatt-database.c
index d6c94058c..d32f616a9 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -3877,6 +3877,10 @@  void btd_gatt_database_server_connected(struct btd_gatt_database *database,
 
 	send_notification_to_device(state, state->pending);
 
+	state = find_device_state(database, &bdaddr, bdaddr_type);
+	if (!state || !state->pending)
+		return;
+
 	free(state->pending->value);
 	free(state->pending);
 	state->pending = NULL;