From: Tom Hromatka Date: Tue, 29 Jul 2025 16:12:21 +0000 (+0000) Subject: api: Fix clang warnings X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f661af05812f185687640acb5923cc9e83acc888;p=thirdparty%2Flibcgroup.git api: Fix clang warnings 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 Signed-off-by: Kamalesh Babulal --- diff --git a/src/api.c b/src/api.c index 234c5b4d..4940e459 100644 --- 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 :)