profiles/a2dp: Fix unchecked return value
authorTedd Ho-Jeong An <tedd.an@intel.com>
Mon, 18 Oct 2021 17:28:29 +0000 (10:28 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:37 +0000 (19:08 +0530)
This patch fixes the unchecked return value(CWE-252) issues reported by
the Coverity.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
profiles/audio/a2dp.c

index 9605ef0..2c2e0c2 100644 (file)
@@ -870,6 +870,7 @@ static void store_remote_seps(struct a2dp_channel *chan)
        char filename[PATH_MAX];
        char dst_addr[18];
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char *data;
        gsize length = 0;
 
@@ -882,7 +883,11 @@ static void store_remote_seps(struct a2dp_channel *chan)
                        btd_adapter_get_storage_dir(device_get_adapter(device)),
                        dst_addr);
        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);
+       }
 
        data = g_key_file_get_string(key_file, "Endpoints", "LastUsed",
                                                                NULL);
@@ -899,7 +904,11 @@ static void store_remote_seps(struct a2dp_channel *chan)
        }
 
        data = g_key_file_to_data(key_file, &length, NULL);
-       g_file_set_contents(filename, data, length, NULL);
+       if (!g_file_set_contents(filename, data, length, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
 
        g_free(data);
        g_key_file_free(key_file);
@@ -1034,6 +1043,7 @@ static void store_last_used(struct a2dp_channel *chan, uint8_t lseid,
                                                        uint8_t rseid)
 {
        GKeyFile *key_file;
+       GError *gerr = NULL;
        char filename[PATH_MAX];
        char dst_addr[18];
        char value[6];
@@ -1046,14 +1056,22 @@ static void store_last_used(struct a2dp_channel *chan, uint8_t lseid,
                btd_adapter_get_storage_dir(device_get_adapter(chan->device)),
                dst_addr);
        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);
+       }
 
        sprintf(value, "%02hhx:%02hhx", lseid, rseid);
 
        g_key_file_set_string(key_file, "Endpoints", "LastUsed", value);
 
        data = g_key_file_to_data(key_file, &len, NULL);
-       g_file_set_contents(filename, data, len, NULL);
+       if (!g_file_set_contents(filename, data, len, &gerr)) {
+               error("Unable set contents for %s: (%s)", filename,
+                                                               gerr->message);
+               g_error_free(gerr);
+       }
 
        g_free(data);
        g_key_file_free(key_file);
@@ -2321,6 +2339,7 @@ static void load_remote_seps(struct a2dp_channel *chan)
        char dst_addr[18];
        char **keys;
        GKeyFile *key_file;
+       GError *gerr = NULL;
 
        ba2str(device_get_address(device), dst_addr);
 
@@ -2328,7 +2347,11 @@ static void load_remote_seps(struct a2dp_channel *chan)
                        btd_adapter_get_storage_dir(device_get_adapter(device)),
                        dst_addr);
        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);
+       }
        keys = g_key_file_get_keys(key_file, "Endpoints", NULL, NULL);
 
        load_remote_sep(chan, key_file, keys);