diff mbox series

[BlueZ,7/9] mesh: Fix unchecked return value

Message ID 20211018172833.534191-8-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.
---
 mesh/keyring.c      |  6 ++++--
 mesh/mesh-io-unit.c |  6 ++++--
 mesh/rpl.c          | 22 ++++++++++++++--------
 mesh/util.c         | 11 ++++++++---
 4 files changed, 30 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/mesh/keyring.c b/mesh/keyring.c
index 4b901643c..51621777d 100644
--- a/mesh/keyring.c
+++ b/mesh/keyring.c
@@ -50,7 +50,8 @@  static int open_key_file(struct mesh_node *node, const char *key_dir,
 
 	if (flags & O_CREAT) {
 		snprintf(fname, PATH_MAX, "%s%s", node_path, key_dir);
-		mkdir(fname, 0755);
+		if (mkdir(fname, 0755) != 0)
+			l_error("Failed to create dir(%d): %s", errno, fname);
 	}
 
 	snprintf(fname, PATH_MAX, "%s%s/%3.3x", node_path, key_dir, idx);
@@ -206,7 +207,8 @@  bool keyring_put_remote_dev_key(struct mesh_node *node, uint16_t unicast,
 
 	snprintf(key_file, PATH_MAX, "%s%s", node_path, dev_key_dir);
 
-	mkdir(key_file, 0755);
+	if (mkdir(key_file, 0755) != 0)
+		l_error("Failed to create dir(%d): %s", errno, key_file);
 
 	for (i = 0; i < count; i++) {
 		snprintf(key_file, PATH_MAX, "%s%s/%4.4x", node_path,
diff --git a/mesh/mesh-io-unit.c b/mesh/mesh-io-unit.c
index c5aae6741..f4b615ac8 100644
--- a/mesh/mesh-io-unit.c
+++ b/mesh/mesh-io-unit.c
@@ -133,7 +133,8 @@  static bool incoming(struct l_io *sio, void *user_data)
 
 		buf[0] = 0;
 		memcpy(buf + 1, pvt->unique_name, size + 1);
-		send(pvt->fd, buf, size + 2, MSG_DONTWAIT);
+		if (send(pvt->fd, buf, size + 2, MSG_DONTWAIT) < 0)
+			l_error("Failed to send(%d)", errno);
 	}
 
 	return true;
@@ -304,7 +305,8 @@  static bool simple_match(const void *a, const void *b)
 static void send_pkt(struct mesh_io_private *pvt, struct tx_pkt *tx,
 							uint16_t interval)
 {
-	send(pvt->fd, tx->pkt, tx->len, MSG_DONTWAIT);
+	if (send(pvt->fd, tx->pkt, tx->len, MSG_DONTWAIT) < 0)
+		l_error("Failed to send(%d)", errno);
 
 	if (tx->delete) {
 		l_queue_remove_if(pvt->tx_pkts, simple_match, tx);
diff --git a/mesh/rpl.c b/mesh/rpl.c
index c53c6fbfd..9a99afe7b 100644
--- a/mesh/rpl.c
+++ b/mesh/rpl.c
@@ -18,6 +18,7 @@ 
 #include <stdio.h>
 #include <unistd.h>
 #include <dirent.h>
+#include <errno.h>
 
 #include <sys/stat.h>
 
@@ -54,9 +55,10 @@  bool rpl_put_entry(struct mesh_node *node, uint16_t src, uint32_t iv_index,
 								iv_index);
 	dir = opendir(src_file);
 
-	if (!dir)
-		mkdir(src_file, 0755);
-	else
+	if (!dir) {
+		if (mkdir(src_file, 0755) != 0)
+			l_error("Failed to create dir: %s", src_file);
+	} else
 		closedir(dir);
 
 	snprintf(src_file, PATH_MAX, "%s%s/%8.8x/%4.4x", node_path, rpl_dir,
@@ -78,8 +80,8 @@  bool rpl_put_entry(struct mesh_node *node, uint16_t src, uint32_t iv_index,
 	iv_index--;
 	snprintf(src_file, PATH_MAX, "%s%s/%8.8x/%4.4x", node_path, rpl_dir,
 								iv_index, src);
-	remove(src_file);
-
+	if (remove(src_file) < 0)
+		l_error("Failed to remove(%d): %s", errno, src_file);
 
 	return result;
 }
@@ -110,7 +112,9 @@  void rpl_del_entry(struct mesh_node *node, uint16_t src)
 		if (entry->d_type == DT_DIR && entry->d_name[0] != '.') {
 			snprintf(rpl_path, PATH_MAX, "%s%s/%s/%4.4x",
 					node_path, rpl_dir, entry->d_name, src);
-			remove(rpl_path);
+			if (remove(rpl_path) < 0)
+				l_error("Failed to remove(%d): %s", errno,
+								rpl_path);
 		}
 	}
 
@@ -251,7 +255,8 @@  void rpl_update(struct mesh_node *node, uint32_t cur)
 
 	/* Make sure path exists */
 	snprintf(path, PATH_MAX, "%s%s", node_path, rpl_dir);
-	mkdir(path, 0755);
+	if (mkdir(path, 0755) != 0)
+		l_error("Failed to create dir(%d): %s", errno, path);
 
 	dir = opendir(path);
 	if (!dir)
@@ -288,6 +293,7 @@  bool rpl_init(const char *node_path)
 		return false;
 
 	snprintf(path, PATH_MAX, "%s%s", node_path, rpl_dir);
-	mkdir(path, 0755);
+	if (mkdir(path, 0755) != 0)
+		l_error("Failed to create dir(%d): %s", errno, path);
 	return true;
 }
diff --git a/mesh/util.c b/mesh/util.c
index 308e7d998..d505e7a0c 100644
--- a/mesh/util.c
+++ b/mesh/util.c
@@ -14,6 +14,7 @@ 
 
 #define _GNU_SOURCE
 #include <dirent.h>
+#include <errno.h>
 #include <ftw.h>
 #include <unistd.h>
 #include <stdio.h>
@@ -117,12 +118,14 @@  int create_dir(const char *dir_name)
 		}
 
 		strncat(dir, prev + 1, next - prev);
-		mkdir(dir, 0755);
+		if (mkdir(dir, 0755) != 0)
+			l_error("Failed to create dir(%d): %s", errno, dir);
 
 		prev = next;
 	}
 
-	mkdir(dir_name, 0755);
+	if (mkdir(dir_name, 0755) != 0)
+		l_error("Failed to create dir(%d): %s", errno, dir_name);
 
 	return 0;
 }
@@ -138,7 +141,9 @@  static int del_fobject(const char *fpath, const struct stat *sb, int typeflag,
 
 	case FTW_SL:
 	default:
-		remove(fpath);
+		if (remove(fpath) < 0)
+			l_error("Failed to remove(%d): %s", errno, fpath);
+
 		l_debug("RM %s", fpath);
 		break;
 	}