[PATCH stalld 50/52] stalld: fix snprintf truncation check in is_runnable

Wander Lairson Costa <[email protected]> Mon, 8 Jun 2026 15:32:00 -0300
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
The truncation check after snprintf() uses > instead of >=. When
snprintf() returns exactly sizeof(stat_path) the output was truncated
but the check does not catch it, allowing a truncated path to reach
open().

Signed-off-by: Wander Lairson Costa <[email protected]>
---
 src/sched_debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/sched_debug.c b/src/sched_debug.c
index d5fbf6d..5110098 100644
--- a/src/sched_debug.c
+++ b/src/sched_debug.c
@@ -309,7 +309,7 @@ static int is_runnable(int pid)
 	if (pid == 0)
 		return 0;
 	retval = snprintf(stat_path, sizeof(stat_path), "/proc/%d/stat", pid);
-	if (retval < 0 || retval > sizeof(stat_path)) {
+	if (retval < 0 || retval >= sizeof(stat_path)) {
 		warn("stat path for task %d too long\n", pid);
 		goto out_error;
 	}
-- 
2.54.0