Skip to content

Commit ce4f9b0

Browse files
committed
proc-utils: Make sure cgroup length is valid before removing EOF char
This fixes a Coverity Scan defect.
1 parent 0f3e005 commit ce4f9b0

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/wp/proc-utils.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,12 @@ wp_proc_utils_get_proc_info (pid_t pid)
179179
/* Get cgroup */
180180
{
181181
g_autofree gchar *path = g_strdup_printf ("/proc/%d/cgroup", pid);
182-
if (g_file_get_contents (path, &ret->cgroup, &length, &error))
183-
ret->cgroup [length - 1] = '\0'; /* Remove EOF character */
184-
else
182+
if (g_file_get_contents (path, &ret->cgroup, &length, &error)) {
183+
if (length > 0)
184+
ret->cgroup [length - 1] = '\0'; /* Remove EOF character */
185+
} else {
185186
wp_warning ("failed to get cgroup for PID %d: %s", pid, error->message);
187+
}
186188
}
187189

188190
/* Get args */

0 commit comments

Comments
 (0)