]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
gmon: Fix UB in sprofil
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Fri, 25 Apr 2025 18:27:08 +0000 (15:27 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Thu, 8 May 2025 12:25:49 +0000 (09:25 -0300)
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

index 0af671d00115674e36a6288cd022a3810f1205a8..0a3d1a8e5010fe0755a49551c4da969d7df961f0 100644 (file)
@@ -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;