@cryptotaxi247 / netdata-1 / commits / e3b4ddedd

Fix coverity issues (#16596)

* Fix coverity issues * Prevent potential overflow

Stelios Fragkakis committed Dec 14, 2023 at 10:50 UTC e3b4ddedd2ffd557a5277fe0a3db78f025b22e2a
3 files changed +21 -21
collectors/log2journal/log2journal-json.c
+15 -15
@@ -47,7 +47,7 @@ static inline bool json_expect_char_after_white_space(LOG_JSON_STATE *js, const
47 }
48
49 snprintf(js->msg, sizeof(js->msg),
50 - "JSON PARSER: character '%c' is not one of the expected characters (%s), at pos %zu",
50 + "JSON PARSER: character '%c' is not one of the expected characters (%s), at pos %u",
51 *s ? *s : '?', expected, js->pos);
52
53 return false;
@@ -62,7 +62,7 @@ static inline bool json_parse_null(LOG_JSON_STATE *js) {
62 }
63 else {
64 snprintf(js->msg, sizeof(js->msg),
65 - "JSON PARSER: expected 'null', found '%.4s' at position %zu", s, js->pos);
65 + "JSON PARSER: expected 'null', found '%.4s' at position %u", s, js->pos);
66 return false;
67 }
68 }
@@ -76,7 +76,7 @@ static inline bool json_parse_true(LOG_JSON_STATE *js) {
76 }
77 else {
78 snprintf(js->msg, sizeof(js->msg),
79 - "JSON PARSER: expected 'true', found '%.4s' at position %zu", s, js->pos);
79 + "JSON PARSER: expected 'true', found '%.4s' at position %u", s, js->pos);
80 return false;
81 }
82 }
@@ -90,7 +90,7 @@ static inline bool json_parse_false(LOG_JSON_STATE *js) {
90 }
91 else {
92 snprintf(js->msg, sizeof(js->msg),
93 - "JSON PARSER: expected 'false', found '%.4s' at position %zu", s, js->pos);
93 + "JSON PARSER: expected 'false', found '%.4s' at position %u", s, js->pos);
94 return false;
95 }
96 }
@@ -112,7 +112,7 @@ static inline bool json_parse_number(LOG_JSON_STATE *js) {
112 // Digits before decimal point
113 while (*s >= '0' && *s <= '9') {
114 if (remaining < 2) {
115 - snprintf(js->msg, sizeof(js->msg), "JSON PARSER: truncated number value at pos %zu", js->pos);
115 + snprintf(js->msg, sizeof(js->msg), "JSON PARSER: truncated number value at position %u", js->pos);
116 return false;
117 }
118 *d++ = *s++;
@@ -126,7 +126,7 @@ static inline bool json_parse_number(LOG_JSON_STATE *js) {
126
127 while (*s >= '0' && *s <= '9') {
128 if (remaining < 2) {
129 - snprintf(js->msg, sizeof(js->msg), "JSON PARSER: truncated fractional part at pos %zu", js->pos);
129 + snprintf(js->msg, sizeof(js->msg), "JSON PARSER: truncated fractional part at position %u", js->pos);
130 return false;
131 }
132 *d++ = *s++;
@@ -147,7 +147,7 @@ static inline bool json_parse_number(LOG_JSON_STATE *js) {
147
148 while (*s >= '0' && *s <= '9') {
149 if (remaining < 2) {
150 - snprintf(js->msg, sizeof(js->msg), "JSON PARSER: truncated exponent at pos %zu", js->pos);
150 + snprintf(js->msg, sizeof(js->msg), "JSON PARSER: truncated exponent at position %u", js->pos);
151 return false;
152 }
153 *d++ = *s++;
@@ -162,7 +162,7 @@ static inline bool json_parse_number(LOG_JSON_STATE *js) {
162 json_process_key_value(js, value, d - value);
163 return true;
164 } else {
165 - snprintf(js->msg, sizeof(js->msg), "JSON PARSER: invalid number format at pos %zu", js->pos);
165 + snprintf(js->msg, sizeof(js->msg), "JSON PARSER: invalid number format at position %u", js->pos);
166 return false;
167 }
168 }
@@ -334,7 +334,7 @@ static inline bool json_parse_string(LOG_JSON_STATE *js) {
334
335 if(remaining < 2) {
336 snprintf(js->msg, sizeof(js->msg),
337 - "JSON PARSER: truncated string value at pos %zu", js->pos);
337 + "JSON PARSER: truncated string value at position %u", js->pos);
338 return false;
339 }
340 else {
@@ -362,7 +362,7 @@ static inline bool json_parse_key_and_push(LOG_JSON_STATE *js) {
362
363 if(js->depth >= JSON_DEPTH_MAX - 1) {
364 snprintf(js->msg, sizeof(js->msg),
365 - "JSON PARSER: object too deep, at pos %zu", js->pos);
365 + "JSON PARSER: object too deep, at position %u", js->pos);
366 return false;
367 }
368
@@ -392,7 +392,7 @@ static inline bool json_parse_key_and_push(LOG_JSON_STATE *js) {
392 else {
393 if(remaining < 2) {
394 snprintf(js->msg, sizeof(js->msg),
395 - "JSON PARSER: key buffer full - keys are too long, at pos %zu", js->pos);
395 + "JSON PARSER: key buffer full - keys are too long, at position %u", js->pos);
396 return false;
397 }
398 *d++ = c;
@@ -417,7 +417,7 @@ static inline bool json_parse_key_and_push(LOG_JSON_STATE *js) {
417 static inline bool json_key_pop(LOG_JSON_STATE *js) {
418 if(js->depth <= 0) {
419 snprintf(js->msg, sizeof(js->msg),
420 - "JSON PARSER: cannot pop a key at depth %zu, at pos %zu", js->depth, js->pos);
420 + "JSON PARSER: cannot pop a key at depth %u, at position %u", js->depth, js->pos);
421 return false;
422 }
423
@@ -465,7 +465,7 @@ static inline bool json_parse_value(LOG_JSON_STATE *js) {
465 }
466
467 snprintf(js->msg, sizeof(js->msg),
468 - "JSON PARSER: unexpected character at pos %zu", js->pos);
468 + "JSON PARSER: unexpected character at position %u", js->pos);
469 return false;
470 }
471
@@ -491,7 +491,7 @@ static inline bool json_key_index_and_push(LOG_JSON_STATE *js, size_t index) {
491 while (*t) {
492 if(remaining < 2) {
493 snprintf(js->msg, sizeof(js->msg),
494 - "JSON PARSER: key buffer full - keys are too long, at pos %zu", js->pos);
494 + "JSON PARSER: key buffer full - keys are too long, at position %u", js->pos);
495 return false;
496 }
497
@@ -613,7 +613,7 @@ bool json_parse_document(LOG_JSON_STATE *js, const char *txt) {
613
614 if(*s) {
615 snprintf(js->msg, sizeof(js->msg),
616 - "JSON PARSER: excess characters found after document is finished, at pos %zu", js->pos);
616 + "JSON PARSER: excess characters found after document is finished, at position %u", js->pos);
617 return false;
618 }
619
collectors/log2journal/log2journal-logfmt.c
+4 -4
@@ -98,7 +98,7 @@ static inline bool logftm_parse_value(LOGFMT_STATE *lfs) {
98
99 if(remaining < 2) {
100 snprintf(lfs->msg, sizeof(lfs->msg),
101 - "LOGFMT PARSER: truncated string value at pos %zu", lfs->pos);
101 + "LOGFMT PARSER: truncated string value at position %u", lfs->pos);
102 return false;
103 }
104 else {
@@ -114,7 +114,7 @@ static inline bool logftm_parse_value(LOGFMT_STATE *lfs) {
114 if(quote != '\0') {
115 if (*s != quote) {
116 snprintf(lfs->msg, sizeof(lfs->msg),
117 - "LOGFMT PARSER: missing quote at pos %zu: '%s'",
117 + "LOGFMT PARSER: missing quote at position %u: '%s'",
118 lfs->pos, s);
119 return false;
120 }
@@ -150,7 +150,7 @@ static inline bool logfmt_parse_key(LOGFMT_STATE *lfs) {
150 else {
151 if(remaining < 2) {
152 snprintf(lfs->msg, sizeof(lfs->msg),
153 - "LOGFMT PARSER: key buffer full - keys are too long, at pos %zu", lfs->pos);
153 + "LOGFMT PARSER: key buffer full - keys are too long, at position %u", lfs->pos);
154 return false;
155 }
156 *d++ = c;
@@ -165,7 +165,7 @@ static inline bool logfmt_parse_key(LOGFMT_STATE *lfs) {
165 s = logfmt_current_pos(lfs);
166 if(*s != '=') {
167 snprintf(lfs->msg, sizeof(lfs->msg),
168 - "LOGFMT PARSER: key is missing the equal sign, at pos %zu", lfs->pos);
168 + "LOGFMT PARSER: key is missing the equal sign, at position %u", lfs->pos);
169 return false;
170 }
171
database/engine/rrdengineapi.c
+2 -2
@@ -811,13 +811,13 @@ static bool rrdeng_load_page_next(struct storage_engine_query_handle *rrddim_han
811 }
812 else {
813 position = (handle->now_s - page_start_time_s) * (entries - 1) / (page_end_time_s - page_start_time_s);
814 - time_t point_end_time_s = page_start_time_s + position * page_update_every_s;
814 + time_t point_end_time_s = page_start_time_s + position * (time_t) page_update_every_s;
815 while(point_end_time_s < handle->now_s && position + 1 < entries) {
816 // https://github.com/netdata/netdata/issues/14411
817 // we really need a while() here, because the delta may be
818 // 2 points at higher tiers
819 position++;
820 - point_end_time_s = page_start_time_s + position * page_update_every_s;
820 + point_end_time_s = page_start_time_s + position * (time_t) page_update_every_s;
821 }
822 handle->now_s = point_end_time_s;
823 }