From 6deb970376e62e7c527e766a195f47b5b81c94de Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Fri, 25 Apr 2025 15:27:08 -0300 Subject: [PATCH] gmon: Fix UB in sprofil UBSAN: Undefined behaviour in ../sysdeps/posix/sprofil.c:272:16 variable length array bound evaluates to non-positive value 0 Move the VLA to after the porfile stop condition (where size might be zero). --- sysdeps/posix/sprofil.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sysdeps/posix/sprofil.c b/sysdeps/posix/sprofil.c index 0af671d001..0a3d1a8e50 100644 --- a/sysdeps/posix/sprofil.c +++ b/sysdeps/posix/sprofil.c @@ -269,7 +269,6 @@ int __sprofil (struct prof *profp, int profcnt, struct timeval *tvp, unsigned int flags) { - struct prof *p[profcnt]; struct itimerval timer; struct sigaction act; int i; @@ -295,6 +294,7 @@ __sprofil (struct prof *profp, int profcnt, struct timeval *tvp, return 0; } + struct prof *p[profcnt]; prof_info.num_regions = 0; prof_info.region = NULL; prof_info.overflow = &default_overflow_region; -- 2.47.2