]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: Fix clang warnings
authorTom Hromatka <tom.hromatka@oracle.com>
Tue, 29 Jul 2025 16:12:21 +0000 (16:12 +0000)
committerKamalesh Babulal <kamalesh.babulal@oracle.com>
Fri, 1 Aug 2025 09:02:21 +0000 (14:32 +0530)
Fix the following clang warnings by reducing the scan size from 4096 to
4095 so that there is room for the null character.

api.c:5173:52: warning: 'fscanf' may overflow; destination buffer in
argument 4 has size 4096, but the corresponding specifier may require
size 4097 [-Wfortify-source]
 5173 |                         ret = fscanf(pid_cgrp_fd,
"%d::%4096s\n", &num, cgrp_path);
      |
^
api.c:5218:69: warning: 'fscanf' may overflow; destination buffer in
argument 5 has size 4096, but the corresponding specifier may require
size 4097 [-Wfortify-source]
 5218 |                 ret = fscanf(pid_cgrp_fd, "%d:%[^:]:%4096s\n",
&num, controllers, cgrp_path);
      |
^

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
src/api.c

index 234c5b4d60afcca57530b5755e531c8010971c30..4940e459ad68e8313addbc54528541f6d0d7ad3b 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -5170,7 +5170,7 @@ int cgroup_get_current_controller_path(pid_t pid, const char *controller, char *
                 * - controller-list is empty
                 */
                if (mode == CGROUP_MODE_UNIFIED || unified) {
-                       ret = fscanf(pid_cgrp_fd, "%d::%4096s\n", &num, cgrp_path);
+                       ret = fscanf(pid_cgrp_fd, "%d::%4095s\n", &num, cgrp_path);
                        if (ret != 2) {
                                /*
                                 * we are interested only in unified format
@@ -5212,10 +5212,10 @@ int cgroup_get_current_controller_path(pid_t pid, const char *controller, char *
                }
 
                /*
-                * 4096 == FILENAME_MAX, keeping the coverity happy with precision
+                * 4095 == FILENAME_MAX - 1, keeping coverity happy with precision
                 * for the cgrp_path.
                 */
-               ret = fscanf(pid_cgrp_fd, "%d:%[^:]:%4096s\n", &num, controllers, cgrp_path);
+               ret = fscanf(pid_cgrp_fd, "%d:%[^:]:%4095s\n", &num, controllers, cgrp_path);
                /*
                 * Magic numbers like "3" seem to be integrating into my daily
                 * life, I need some magic to help make them disappear :)