From 042360b02ebc476b8627e3be8723a8f2069dfc6d Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Tue, 29 Jul 2025 16:18:53 +0000 Subject: [PATCH] cgexec: Fix clang warnings Fix the following clang warnings by shrinking the scan size from 4096 to 4095 to allow room for the null terminating character. cgexec.c:294:47: warning: 'sscanf' may overflow; destination buffer in argument 4 has size 4096, but the corresponding specifier may require size 4097 [-Wfortify-source] 294 | ret = sscanf(buffer, "%d::%4096s\n", &idx, cgrp_name); | ^ cgexec.c:296:63: warning: 'sscanf' may overflow; destination buffer in argument 5 has size 4096, but the corresponding specifier may require size 4097 [-Wfortify-source] 296 | ret = sscanf(buffer, "%d:%[^:]:%4096s\n", &idx, ctrl_name, cgrp_name); | ^ cgexec.c:423:40: warning: 'sscanf' may overflow; destination buffer in argument 3 has size 4096, but the corresponding specifier may require size 4097 [-Wfortify-source] 423 | ret = sscanf(buffer, "%*s %4096s\n", cgrp_path); | ^ Signed-off-by: Tom Hromatka Signed-off-by: Kamalesh Babulal --- src/tools/cgexec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/cgexec.c b/src/tools/cgexec.c index 448d3ff9..04fc0989 100644 --- a/src/tools/cgexec.c +++ b/src/tools/cgexec.c @@ -291,9 +291,9 @@ static pid_t find_scope_pid(pid_t pid) /* read according to the cgroup mode */ if (strstr(buffer, "::")) - ret = sscanf(buffer, "%d::%4096s\n", &idx, cgrp_name); + ret = sscanf(buffer, "%d::%4095s\n", &idx, cgrp_name); else - ret = sscanf(buffer, "%d:%[^:]:%4096s\n", &idx, ctrl_name, cgrp_name); + ret = sscanf(buffer, "%d:%[^:]:%4095s\n", &idx, ctrl_name, cgrp_name); if (ret != 2 && ret != 3) { err("Unrecognized cgroup file format: %s\n", buffer); @@ -420,7 +420,7 @@ static void find_mnt_point(const char * const controller, char **mnt_point) if (!strstr(buffer, controller)) continue; - ret = sscanf(buffer, "%*s %4096s\n", cgrp_path); + ret = sscanf(buffer, "%*s %4095s\n", cgrp_path); if (ret != 1) { err("Failed during read of %s:%s\n", proc_mount, strerror(errno)); goto out; -- 2.47.2