diff mbox series

[BlueZ,v2,5/5] settings: add NULL checks to gatt_db_load()

Message ID 20240705075709.26809-6-r.smirnov@omp.ru (mailing list archive)
State Accepted
Commit 804696dee79515e2001ec445ae218d7b42887c37
Headers show
Series fix error found by SVACE static analyzer #2 | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Roman Smirnov July 5, 2024, 7:57 a.m. UTC
It is necessary to prevent dereferencing of null pointers.

Found with the SVACE static analysis tool.
---
 src/settings.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/src/settings.c b/src/settings.c
index 996eaacd3..b61e694f1 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -232,7 +232,7 @@  static int gatt_db_load(struct gatt_db *db, GKeyFile *key_file, char **keys)
 		value = g_key_file_get_string(key_file, "Attributes", *handle,
 									NULL);
 
-		if (sscanf(value, "%[^:]:", type) != 1) {
+		if (!value || sscanf(value, "%[^:]:", type) != 1) {
 			g_free(value);
 			return -EIO;
 		}
@@ -255,7 +255,7 @@  static int gatt_db_load(struct gatt_db *db, GKeyFile *key_file, char **keys)
 		value = g_key_file_get_string(key_file, "Attributes", *handle,
 									NULL);
 
-		if (sscanf(value, "%[^:]:", type) != 1) {
+		if (!value || sscanf(value, "%[^:]:", type) != 1) {
 			g_free(value);
 			return -EIO;
 		}