From: Kamalesh Babulal Date: Fri, 23 Jun 2023 06:19:04 +0000 (+0530) Subject: api: add ret value check in cgroup_get_current_controller_path() X-Git-Tag: v3.1.0~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9be563218aba0de080cd4beefb46beec8d620d5d;p=thirdparty%2Flibcgroup.git api: add ret value check in cgroup_get_current_controller_path() Fix unchecked return value, reported by the Coverity tool: CID 320874 (#1 of 1): Unchecked return value from library (CHECKED_RETURN)13. check_return: Calling fscanf(pid_cgroup_fd, "%*[^\n]\n") without checking return value. This library function may fail and return an error code. add the missing return value check from fscanf() in cgroup_get_current_controller_path() Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- diff --git a/src/api.c b/src/api.c index 1d835c4d..5428cc34 100644 --- a/src/api.c +++ b/src/api.c @@ -4914,8 +4914,9 @@ int cgroup_get_current_controller_path(pid_t pid, const char *controller, char * * line, skip this line. */ if (unified) { - fscanf(pid_cgroup_fd, "%*[^\n]\n"); - continue; + ret = fscanf(pid_cgroup_fd, "%*[^\n]\n"); + if (ret == 0) + continue; } cgroup_warn("read failed for pid_cgroup_fd ret %d\n", ret);