From ce4f9b08a9d5e014f778160a30b36e1723ea0dc7 Mon Sep 17 00:00:00 2001 From: Julian Bouzas Date: Wed, 5 Mar 2025 13:36:04 -0500 Subject: [PATCH] proc-utils: Make sure cgroup length is valid before removing EOF char This fixes a Coverity Scan defect. --- lib/wp/proc-utils.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/wp/proc-utils.c b/lib/wp/proc-utils.c index fbd39c04..17450a5a 100644 --- a/lib/wp/proc-utils.c +++ b/lib/wp/proc-utils.c @@ -179,10 +179,12 @@ wp_proc_utils_get_proc_info (pid_t pid) /* Get cgroup */ { g_autofree gchar *path = g_strdup_printf ("/proc/%d/cgroup", pid); - if (g_file_get_contents (path, &ret->cgroup, &length, &error)) - ret->cgroup [length - 1] = '\0'; /* Remove EOF character */ - else + if (g_file_get_contents (path, &ret->cgroup, &length, &error)) { + if (length > 0) + ret->cgroup [length - 1] = '\0'; /* Remove EOF character */ + } else { wp_warning ("failed to get cgroup for PID %d: %s", pid, error->message); + } } /* Get args */