From 03cfb388ae416c2c6dd5fda835f30f30a042ec91 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Wed, 17 Jul 2024 13:00:48 +0530 Subject: [PATCH] src/api: Fix ret value in cgroup_get_current_controller_path() The CodeQL reported a warning: "Incorrect return-value check for a 'scanf'-like function" More information about the warning: https://github.com/libcgroup/libcgroup/security/code-scanning/16 Fix the warning by adding an additional "EOF" check for the ret value from fscanf() in the cgroup_get_current_controller_path() Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- src/api.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/api.c b/src/api.c index 09f04783..984ca75f 100644 --- a/src/api.c +++ b/src/api.c @@ -5019,6 +5019,12 @@ int cgroup_get_current_controller_path(pid_t pid, const char *controller, char * ret = fscanf(pid_cgroup_fd, "%*[^\n]\n"); if (ret == 0) continue; + + if (ret == EOF) { + last_errno = errno; + ret = ECGEOF; + goto done; + } } cgroup_warn("read failed for pid_cgroup_fd ret %d\n", ret); -- 2.47.3