]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: add ret value check in cgroup_get_current_controller_path()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 23 Jun 2023 06:19:04 +0000 (11:49 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Fri, 23 Jun 2023 13:46:42 +0000 (07:46 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 1d835c4d9b1b3fa51721af65bf11977a44e746bb..5428cc343c1ff4dd72749b714f8eb801abf2b95d 100644 (file)
--- 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);