musllvm

musl and LLVM cross-toolchain build system
git clone https://git.daat.foo/musllvm.git
Log | Files | Refs | README | LICENSE

006-228da39e38c1cae13cbe637e771412c1984dba5d.patch (1480B)


      1 From 228da39e38c1cae13cbe637e771412c1984dba5d Mon Sep 17 00:00:00 2001
      2 From: Rich Felker <dalias@aerifal.cx>
      3 Date: Thu, 9 Apr 2026 22:51:30 -0400
      4 Subject: qsort: fix leonardo heap corruption from bug in doubleword ctz
      5  primitive
      6 
      7 the pntz function, implementing a "count trailing zeros" variant for a
      8 bit vector consisting of two size_t words, erroneously returned zero
      9 rather than the number of bits in the low word when the first bit set
     10 was the low bit of the high word.
     11 
     12 as a result, a loop in the trinkle function which should have a
     13 guaranteed small bound on the number of iterations, could run
     14 unboundedly, thereby overflowing a stack-based working-space array
     15 which was sized for the bound.
     16 
     17 CVE-2026-40200 has been assigned for this issue.
     18 ---
     19  src/stdlib/qsort.c | 8 ++++----
     20  1 file changed, 4 insertions(+), 4 deletions(-)
     21 
     22 diff --git a/src/stdlib/qsort.c b/src/stdlib/qsort.c
     23 index ab79dc6f..13219ab3 100644
     24 --- a/src/stdlib/qsort.c
     25 +++ b/src/stdlib/qsort.c
     26 @@ -34,11 +34,11 @@
     27  
     28  typedef int (*cmpfun)(const void *, const void *, void *);
     29  
     30 +/* returns index of first bit set, excluding the low bit assumed to always
     31 + * be set, starting from low bit of p[0] up through high bit of p[1] */
     32  static inline int pntz(size_t p[2]) {
     33 -	int r = ntz(p[0] - 1);
     34 -	if(r != 0 || (r = 8*sizeof(size_t) + ntz(p[1])) != 8*sizeof(size_t)) {
     35 -		return r;
     36 -	}
     37 +	if (p[0] != 1) return ntz(p[0] - 1);
     38 +	if (p[1]) return 8*sizeof(size_t) + ntz(p[1]);
     39  	return 0;
     40  }
     41  
     42 -- 
     43 cgit v1.2.1
     44