summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStelios Fragkakis <52996999+stelfrag@users.noreply.github.com>2024-01-12 12:40:03 +0200
committerGitHub <noreply@github.com>2024-01-12 12:40:03 +0200
commit86526775f1ed09d94a9b28665ce64a1f614d7c5b (patch)
tree1b1291ed56ee6985fdd19901e1fe67e014ea3b62
parent7fce3dcd9cb9eb87509a9cec80e51fefd0a971ff (diff)
Fix coverity issues (#16766)
Fix warning note: ‘snprintf’ output between 2 and 4352 bytes into a destination of size 4096 CID 413881: Control flow issues (DEADCODE) CID 413882: Control flow issues (DEADCODE) CID 413883: Resource leaks (RESOURCE_LEAK)
-rw-r--r--daemon/config/dyncfg-unittest.c7
-rw-r--r--web/api/web_api_v1.c6
2 files changed, 5 insertions, 8 deletions
diff --git a/daemon/config/dyncfg-unittest.c b/daemon/config/dyncfg-unittest.c
index 25838e8154..a1c7dbeb5d 100644
--- a/daemon/config/dyncfg-unittest.c
+++ b/daemon/config/dyncfg-unittest.c
@@ -516,8 +516,8 @@ static int dyncfg_unittest_run(const char *cmd, BUFFER *wb, const char *payload,
}
static void dyncfg_unittest_cleanup_files(void) {
- char path[PATH_MAX];
- snprintfz(path, sizeof(path), "%s/%s", netdata_configured_varlib_dir, "config");
+ char path[FILENAME_MAX];
+ snprintfz(path, sizeof(path) - 1, "%s/%s", netdata_configured_varlib_dir, "config");
DIR *dir = opendir(path);
if (!dir) {
@@ -526,7 +526,7 @@ static void dyncfg_unittest_cleanup_files(void) {
}
struct dirent *entry;
- char filename[FILENAME_MAX];
+ char filename[FILENAME_MAX + sizeof(entry->d_name)];
while ((entry = readdir(dir)) != NULL) {
if ((entry->d_type == DT_REG || entry->d_type == DT_LNK) && strstartswith(entry->d_name, "unittest:") && strendswith(entry->d_name, ".dyncfg")) {
snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name);
@@ -788,5 +788,6 @@ int dyncfg_unittest(void) {
netdata_thread_join(thread, &ptr);
dyncfg_unittest_cleanup_files();
dictionary_destroy(dyncfg_unittest_data.nodes);
+ buffer_free(wb);
return __atomic_load_n(&dyncfg_unittest_data.errors, __ATOMIC_RELAXED) > 0 ? 1 : 0;
}
diff --git a/web/api/web_api_v1.c b/web/api/web_api_v1.c
index 5033002d74..b0444d7cd8 100644
--- a/web/api/web_api_v1.c
+++ b/web/api/web_api_v1.c
@@ -1509,11 +1509,7 @@ static int web_client_api_request_v1_config(RRDHOST *host, struct web_client *w,
char transaction[UUID_COMPACT_STR_LEN];
uuid_unparse_lower_compact(w->transaction, transaction);
- size_t len = (action ? strlen(action) : 0)
- + (id ? strlen(id) : 0)
- + (path ? strlen(path) : 0)
- + (add_name ? strlen(add_name) : 0)
- + 100;
+ size_t len = strlen(action) + (id ? strlen(id) : 0) + strlen(path) + (add_name ? strlen(add_name) : 0) + 100;
char cmd[len];
if(strcmp(action, "tree") == 0)