Fix memory-safety and correctness bugs surfaced by Coverity audit (part 3) (#22268)
* xenstat: skip domains without libxl domain info Coverity CID 413854 (UNINIT): skip the current domain when `libxl_domain_info()` fails before hashing or storing its UUID. This avoids using an uninitialized `uuid` buffer on the error path in `xenstat_collect()`. * datetime: fix rfc3339 fractional scaling Coverity CID 457729 (INTEGER_OVERFLOW): print_fraction() underflowed its loop bound when callers requested 7-9 fractional digits. Scale microseconds down for shorter output and pad zeros for 7-9 digits so the formatter preserves the existing 1..9-digit contract without hanging. * libnetdata: grow cpuset cpu parser buffer Coverity CID 425864 (TAINTED_SCALAR): os_read_cpuset_cpus() sized its static buffer from the first caller's system_cpus argument, and startup can first call it with 0. Derive a non-zero CPU baseline when needed and grow the buffer before reading cpuset.cpus so long CPU lists are not truncated into wrong counts or out-of-bounds parsing. * proc: fix mdstat obsolete chart lookup key mismatch Chart creation in proc_mdstat.c builds the short chart id "<raid>_<suffix>" and passes it to rrdset_create_localhost("mdstat", id, ...); the RRD layer later prefixes "mdstat." when constructing the full chart id. make_chart_obsolete() was instead formatting the full "mdstat.<raid>_<suffix>" directly into a 50-byte buffer and calling rrdset_find_active_byname_localhost, which means the two paths used different truncation boundaries. For long but valid md names (mdadm(8) allows up to 32 characters), the create-path chart was longer than what obsolete-path could build, so the lookup missed and the array's "availability" chart was never marked obsolete. Build the same short chart id in the obsolete path and resolve it through the type/id lookup helper so long valid md names match the created chart. Related: Coverity CID 414643 flagged an OVERRUN on this line; the trace is a tool-model false positive (no OOB in the current code), but investigating it surfaced the real correctness bug fixed here. * proc.plugin: avoid uaf in power supply property loop Coverity CID 348628 (USE_AFTER_FREE): do_sys_class_power_supply() could free the current power supply while iterating its property list, then evaluate the outer loop increment on the freed property node. Store the next property before the inner loop and stop iterating once the error path frees the power supply. * rrdhost: fix unlocked receiver status snapshot Coverity CID 410067 (MISSING_LOCK): rrdhost_status_ingest() read receiver status fields without receiver_lock while the receiver thread updated the same state under that lock. Snapshot the receiver status block under the lock before deriving ingest status so status reporting no longer races with connect and disconnect updates. * aclk: fix pending request cancellation race Coverity CID 410087 (MISSING_LOCK): aclk_web_client_interrupt_cb() read pending_req_list.canceled from a libuv worker while cancel paths updated the same flag from the ACLK side. Switch the cancel flag accesses to atomic load/store so query cancellation stays lock-free on the hot callback path without racing across threads. * statsd: lock histogram sample buffer access Coverity CID 410124 (MISSING_LOCK): histogram and timer samples updated the shared buffer partly outside `m->histogram.ext->mutex` while the flush path sorted the same buffer under that lock. Keep reset, growth, append, and flush snapshot on the same mutex so samples are not dropped or read from a partially synchronized buffer. * apps.plugin: unlock mutex before print exit Coverity CID 381151 (LOCK): the stored trace points to stale line numbers, but the current print-tree exit path still called exit() while holding apps_and_stdout_mutex. Unlock the mutex after printing and before exit() so the module destructor does not destroy a locked uv_mutex_t. --------- Co-authored-by: Costa Tsaousis <costa@netdata.cloud>