diff mbox series

[BlueZ,4/9] plugins/admin: Fix unchecked return value

Message ID 20211018172833.534191-5-hj.tedd.an@gmail.com (mailing list archive)
State Accepted
Delegated to: Luiz Von Dentz
Headers show
Series Fix unchecked return value | expand

Checks

Context Check Description
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint success Gitlint PASS

Commit Message

Tedd Ho-Jeong An Oct. 18, 2021, 5:28 p.m. UTC
From: Tedd Ho-Jeong An <tedd.an@intel.com>

This patch fixes the unchecked return value(CWE-252) issues reported by
the Coverity.
---
 plugins/admin.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/plugins/admin.c b/plugins/admin.c
index 7b7190a06..a8e7d2cd7 100644
--- a/plugins/admin.c
+++ b/plugins/admin.c
@@ -247,6 +247,7 @@  failed:
 static void store_policy_settings(struct btd_admin_policy *admin_policy)
 {
 	GKeyFile *key_file = NULL;
+	GError *gerr = NULL;
 	char *filename = ADMIN_POLICY_STORAGE;
 	char *key_file_data = NULL;
 	char **uuid_strs = NULL;
@@ -274,7 +275,12 @@  static void store_policy_settings(struct btd_admin_policy *admin_policy)
 	}
 
 	key_file_data = g_key_file_to_data(key_file, &length, NULL);
-	g_file_set_contents(ADMIN_POLICY_STORAGE, key_file_data, length, NULL);
+	if (!g_file_set_contents(ADMIN_POLICY_STORAGE, key_file_data, length,
+								&gerr)) {
+		error("Unable set contents for %s: (%s)", ADMIN_POLICY_STORAGE,
+								gerr->message);
+		g_error_free(gerr);
+	}
 
 	g_free(key_file_data);
 	free_uuid_strings(uuid_strs, num_uuids);
@@ -335,6 +341,7 @@  failed:
 static void load_policy_settings(struct btd_admin_policy *admin_policy)
 {
 	GKeyFile *key_file;
+	GError *gerr = NULL;
 	char *filename = ADMIN_POLICY_STORAGE;
 	struct stat st;
 
@@ -343,7 +350,11 @@  static void load_policy_settings(struct btd_admin_policy *admin_policy)
 
 	key_file = g_key_file_new();
 
-	g_key_file_load_from_file(key_file, filename, 0, NULL);
+	if (!g_key_file_load_from_file(key_file, filename, 0, &gerr)) {
+		error("Unable to load key file from %s: (%s)", filename,
+								gerr->message);
+		g_error_free(gerr);
+	}
 
 	key_file_load_service_allowlist(key_file, admin_policy);