From: Kamalesh Babulal Date: Wed, 17 Jul 2024 07:30:48 +0000 (+0530) Subject: src/api: Fix ret value in cgroup_get_current_controller_path() X-Git-Tag: v3.2.0~89 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=03cfb388ae416c2c6dd5fda835f30f30a042ec91;p=thirdparty%2Flibcgroup.git 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 --- 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);