obexd: Fix unchecked return value
authorTedd Ho-Jeong An <tedd.an@intel.com>
Mon, 18 Oct 2021 17:28:32 +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>
obexd/client/transfer.c
obexd/plugins/pcsuite.c
obexd/src/main.c

index 4ad4582..d8b9f30 100755 (executable)
@@ -420,8 +420,11 @@ static void obc_transfer_free(struct obc_transfer *transfer)
 
        if (transfer->op == G_OBEX_OP_GET &&
                                transfer->status != TRANSFER_STATUS_COMPLETE &&
-                               transfer->filename)
-               remove(transfer->filename);
+                               transfer->filename) {
+               if (remove(transfer->filename) < 0)
+                       error("remove(%s): %s(%d)", transfer->filename,
+                                                       strerror(errno), errno);
+       }
 
        if (transfer->fd > 0)
                close(transfer->fd);
@@ -521,7 +524,10 @@ static gboolean transfer_open(struct obc_transfer *transfer, int flags,
        }
 
        if (transfer->filename == NULL) {
-               remove(filename); /* remove always only if NULL was given */
+               /* remove always only if NULL was given */
+               if (remove(filename) < 0)
+                       error("remove(%s): %s(%d)", filename, strerror(errno),
+                                                                       errno);
                g_free(filename);
        } else {
                g_free(transfer->filename);
index c622687..3ae4e72 100755 (executable)
@@ -219,7 +219,9 @@ static void pcsuite_disconnect(struct obex_session *os, void *user_data)
                close(pcsuite->fd);
 
        if (pcsuite->lock_file) {
-               remove(pcsuite->lock_file);
+               if (remove(pcsuite->lock_file) < 0)
+                       error("remove(%s): %s(%d)", pcsuite->lock_file,
+                                                       strerror(errno), errno);
                g_free(pcsuite->lock_file);
        }
 
index 12cdcca..3bf4e5c 100755 (executable)
@@ -277,7 +277,9 @@ int main(int argc, char *argv[])
        if (option_root == NULL) {
                option_root = g_build_filename(g_get_user_cache_dir(), "obexd",
                                                                        NULL);
-               g_mkdir_with_parents(option_root, 0700);
+               if (g_mkdir_with_parents(option_root, 0700) < 0)
+                       error("Failed to create dir(%d): %s", errno,
+                                                               option_root);
        }
 
        if (option_root[0] != '/') {