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)
Stelios Fragkakis committed
Jan 12, 2024 at 12:40 UTC
86526775f1ed09d94a9b28665ce64a1f614d7c5b
2 files changed
+5
-8
daemon/config/dyncfg-unittest.c
+4
-3
@@ -516,8 +516,8 @@ static int dyncfg_unittest_run(const char *cmd, BUFFER *wb, const char *payload,
516
}
517
518
static void dyncfg_unittest_cleanup_files(void) {
519
- char path[PATH_MAX];
520
- snprintfz(path, sizeof(path), "%s/%s", netdata_configured_varlib_dir, "config");
519
+ char path[FILENAME_MAX];
520
+ snprintfz(path, sizeof(path) - 1, "%s/%s", netdata_configured_varlib_dir, "config");
521
522
DIR *dir = opendir(path);
523
if (!dir) {
@@ -526,7 +526,7 @@ static void dyncfg_unittest_cleanup_files(void) {
526
}
527
528
struct dirent *entry;
529
- char filename[FILENAME_MAX];
529
+ char filename[FILENAME_MAX + sizeof(entry->d_name)];
530
while ((entry = readdir(dir)) != NULL) {
531
if ((entry->d_type == DT_REG || entry->d_type == DT_LNK) && strstartswith(entry->d_name, "unittest:") && strendswith(entry->d_name, ".dyncfg")) {
532
snprintf(filename, sizeof(filename), "%s/%s", path, entry->d_name);
@@ -788,5 +788,6 @@ int dyncfg_unittest(void) {
788
netdata_thread_join(thread, &ptr);
789
dyncfg_unittest_cleanup_files();
790
dictionary_destroy(dyncfg_unittest_data.nodes);
791
+ buffer_free(wb);
792
return __atomic_load_n(&dyncfg_unittest_data.errors, __ATOMIC_RELAXED) > 0 ? 1 : 0;
793
}
web/api/web_api_v1.c
+1
-5
@@ -1509,11 +1509,7 @@ static int web_client_api_request_v1_config(RRDHOST *host, struct web_client *w,
1509
char transaction[UUID_COMPACT_STR_LEN];
1510
uuid_unparse_lower_compact(w->transaction, transaction);
1511
1512
- size_t len = (action ? strlen(action) : 0)
1513
- + (id ? strlen(id) : 0)
1514
- + (path ? strlen(path) : 0)
1515
- + (add_name ? strlen(add_name) : 0)
1516
- + 100;
1512
+ size_t len = strlen(action) + (id ? strlen(id) : 0) + strlen(path) + (add_name ? strlen(add_name) : 0) + 100;
1513
1514
char cmd[len];
1515
if(strcmp(action, "tree") == 0)