Fix coverity issues (#19317)
Fix CID 443730,384403,440000,414453,414452,410072
Stelios Fragkakis committed
Jan 9, 2025 at 12:06 UTC
0d4f8023de9cdc27c231ed33928900b2bebd013b
5 files changed
+26
-6
src/collectors/diskspace.plugin/plugin_diskspace.c
+2
@@ -612,7 +612,9 @@ static void diskspace_main_cleanup(void *pptr) {
612
if (diskspace_slow_thread)
613
nd_thread_join(diskspace_slow_thread);
614
615
+ netdata_mutex_lock(&slow_mountinfo_mutex);
616
free_basic_mountinfo_list(slow_mountinfo_tmp_root);
617
+ netdata_mutex_unlock(&slow_mountinfo_mutex);
618
619
static_thread->enabled = NETDATA_MAIN_THREAD_EXITED;
620
}
src/daemon/dyncfg/dyncfg-files.c
+20
-4
@@ -142,12 +142,28 @@ void dyncfg_file_load(const char *d_name) {
142
143
if (read_payload) {
144
// Determine the actual size of the remaining file content
145
+ int rc = 0;
146
long saved_position = ftell(fp); // Save current position
146
- fseek(fp, 0, SEEK_END);
147
- long total_size = ftell(fp); // Total size of the file
148
- size_t actual_size = total_size - saved_position; // Calculate remaining content size
149
- fseek(fp, saved_position, SEEK_SET); // Reset file pointer to the beginning of the payload
147
148
+ long total_size = 0;
149
+ size_t actual_size = 0;
150
+ if (saved_position != -1) {
151
+ rc = fseek(fp, 0, SEEK_END);
152
+ if (!rc) {
153
+ total_size = ftell(fp); // Total size of the file
154
+ actual_size = total_size - saved_position; // Calculate remaining content size
155
+ rc = fseek(fp, saved_position, SEEK_SET); // Reset file pointer to the beginning of the payload
156
+ }
157
+ }
158
+
159
+ // Check if any of the system calls failed
160
+ if (rc || saved_position == -1 || total_size == -1) {
161
+ nd_log(NDLS_DAEMON, NDLP_ERR, "DYNCFG: error while accessing '%s' to calculate the %s.", filename,
162
+ saved_position == -1 ? "payload position" : "file size");
163
+ fclose(fp);
164
+ dyncfg_cleanup(&tmp);
165
+ return;
166
+ }
167
// Use actual_size instead of content_length to handle the whole remaining file
168
tmp.dyncfg.payload = buffer_create(actual_size, NULL);
169
tmp.dyncfg.payload->content_type = content_type;
src/database/engine/journalfile.c
+4
@@ -1398,6 +1398,10 @@ void journalfile_migrate_to_v2_callback(Word_t section, unsigned datafile_fileno
1398
max_time_s = MAX(max_time_s, metric_info->last_time_s);
1399
}
1400
1401
+ // Check if not properly set in the loop above to prevent overflow
1402
+ if (min_time_s == LONG_MAX)
1403
+ min_time_s = 0;
1404
+
1405
// Store in the header
1406
j2_header.start_time_ut = min_time_s * USEC_PER_SEC;
1407
j2_header.end_time_ut = max_time_s * USEC_PER_SEC;
src/libnetdata/facets/logs_query_status.h
-1
@@ -561,7 +561,6 @@ static inline bool lqs_request_parse_GET(LOGS_QUERY_STATUS *lqs, BUFFER *wb, cha
561
LQS_SOURCE_TYPE t = LQS_FUNCTION_GET_INTERNAL_SOURCE_TYPE(value);
562
if(t != LQS_SOURCE_TYPE_NONE) {
563
rq->source_type |= t;
564
- value = NULL;
564
}
565
else {
566
// else, match the source, whatever it is
src/web/api/formatters/json_wrapper.c
-1
@@ -1169,7 +1169,6 @@ static void query_target_detailed_objects_tree(BUFFER *wb, RRDR *r, RRDR_OPTIONS
1169
}
1170
buffer_json_object_close(wb); // contexts
1171
buffer_json_object_close(wb); // host
1172
- last_host = NULL;
1172
}
1173
1174
buffer_json_member_add_object(wb, host->machine_guid);