From: Tedd Ho-Jeong An Date: Mon, 18 Oct 2021 17:28:31 +0000 (-0700) Subject: mesh: Fix unchecked return value X-Git-Tag: submit/tizen/20220313.220938~80 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72d42d8e1df25c7eb737f4055c22b936b6e72533;p=platform%2Fupstream%2Fbluez.git mesh: Fix unchecked return value This patch fixes the unchecked return value(CWE-252) issues reported by the Coverity. Signed-off-by: Anuj Jain Signed-off-by: Ayush Garg --- diff --git a/mesh/keyring.c b/mesh/keyring.c index 76a4090e..fdef5d22 100644 --- a/mesh/keyring.c +++ b/mesh/keyring.c @@ -51,7 +51,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); @@ -207,7 +208,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 3b6abb0c..400248d4 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 904cef7c..37742638 100644 --- a/mesh/rpl.c +++ b/mesh/rpl.c @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -57,9 +58,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, @@ -81,8 +83,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; } @@ -113,7 +115,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); } } @@ -254,7 +258,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) @@ -291,6 +296,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 7a120e03..a45a2938 100644 --- a/mesh/util.c +++ b/mesh/util.c @@ -14,6 +14,7 @@ #include +#include #include #include #include @@ -116,12 +117,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; } @@ -137,7 +140,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; }