@cryptotaxi247 / netdata-1 / commits / 83179b715

Fix based on Coverity and Sonar audits (part 1) (#22329)

* cgroups: fix unsigned underflow OOB in convert_cgroup_to_systemd_service Sonar c:S3519 (BLOCKER): the reverse-scan loops in convert_cgroup_to_systemd_service() used `while (len--)` on a `size_t`, so when the input contained no separator the loop ran to completion and the post-decrement on len == 0 wrapped to SIZE_MAX. The subsequent `if (len)` was true and `s[len] = '\0'` wrote far out of bounds. The dot-search was the explicitly flagged path; the slash-search had the same wrap pattern but was accidentally benign because `&s[SIZE_MAX + 1]` wrapped back to `&s[0]`. Replace both reverse scans with strrchr() and an explicit non-NULL, non-leading check. Preserves the existing behavior for valid inputs (separator at index > 0 truncates / repositions; separator at index 0 or absent leaves the string unchanged) and removes the unsigned-underflow path. * apps.plugin: replace single-iteration while with if in comm_from_cmdline_sanitized Sonar c:S1751: comm_from_cmdline_sanitized() used `while (start)` to process the first occurrence of `comm` in the duplicated command-line buffer, but the body unconditionally returns and `start` is never updated -- the loop could never iterate twice. Replace with `if (start)` for accurate intent. No behavior change. * ebpf.plugin: drop unsigned unary minus in zombie counter computation Sonar c:S876: ebpf_update_global_publish() computed `zombie = exit + (-release_task)` via in-place negation of the unsigned release_task counter. The unary minus on uint64_t is well-defined (modular arithmetic) but is a code smell and was unnecessary -- the intent was simple subtraction. Replace with a direct `(long)exit - (long)release_task`, matching the pattern used for `pvc->running` two lines above. Drop the in-place mutation; the release_task counter is not read elsewhere after this block. Numerical result is identical. --------- Co-authored-by: Costa Tsaousis <costa@netdata.cloud>

Stelios Fragkakis committed May 6, 2026 at 22:51 UTC 83179b715ba6a60e4173b53ec521d07a37c2d746
3 files changed +8 -21
src/collectors/apps.plugin/apps_pid.c
+1 -1
@@ -441,7 +441,7 @@ static inline STRING *comm_from_cmdline_sanitized(STRING *comm, STRING *cmdline)
441
442 size_t comm_len = string_strlen(comm);
443 char *start = strstr(buf, string2str(comm));
444 - while (start) {
444 + if (start) {
445 char *end = start + comm_len;
446 while (*end &&
447 !isspace((uint8_t) *end) &&
src/collectors/cgroups.plugin/cgroup-discovery.c
+6 -18
@@ -284,26 +284,14 @@ static inline void convert_cgroup_to_systemd_service(struct cgroup *cg) {
284 char *s = buffer;
285
286 // skip to the last slash
287 - size_t len = strlen(s);
288 - while (len--) {
289 - if (unlikely(s[len] == '/')) {
290 - break;
291 - }
292 - }
293 - if (len) {
294 - s = &s[len + 1];
295 - }
287 + char *slash = strrchr(s, '/');
288 + if (unlikely(slash && slash != s))
289 + s = slash + 1;
290
291 // remove extension
298 - len = strlen(s);
299 - while (len--) {
300 - if (unlikely(s[len] == '.')) {
301 - break;
302 - }
303 - }
304 - if (len) {
305 - s[len] = '\0';
306 - }
292 + char *dot = strrchr(s, '.');
293 + if (unlikely(dot && dot != s))
294 + *dot = '\0';
295
296 freez(cg->name);
297 cg->name = strdupz(s);
src/collectors/ebpf.plugin/ebpf_process.c
+1 -2
@@ -314,8 +314,7 @@ static void ebpf_update_global_publish(
314
315 pvc->running =
316 (long)publish[NETDATA_KEY_PUBLISH_PROCESS_FORK].ncall - (long)publish[NETDATA_KEY_PUBLISH_PROCESS_CLONE].ncall;
317 - publish[NETDATA_KEY_PUBLISH_PROCESS_RELEASE_TASK].ncall = -publish[NETDATA_KEY_PUBLISH_PROCESS_RELEASE_TASK].ncall;
318 - pvc->zombie = (long)publish[NETDATA_KEY_PUBLISH_PROCESS_EXIT].ncall +
317 + pvc->zombie = (long)publish[NETDATA_KEY_PUBLISH_PROCESS_EXIT].ncall -
318 (long)publish[NETDATA_KEY_PUBLISH_PROCESS_RELEASE_TASK].ncall;
319 }
320