]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
src/api: Fix ret value in cgroup_get_current_controller_path()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 17 Jul 2024 07:30:48 +0000 (13:00 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 18 Jul 2024 16:15:03 +0000 (10:15 -0600)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 09f047832928595689f972101c56d4b4b1975e2c..984ca75f8b7e935225d2bb3cbd74ef2658b11b7c 100644 (file)
--- 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);