]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
math: Fix UB in setayload
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>
Mon, 21 Apr 2025 18:12:21 +0000 (15:12 -0300)
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>
Wed, 7 May 2025 17:21:21 +0000 (14:21 -0300)
The code can shift the 1ULL for value larger than 63 depending of
the exponent value.  Add a check prior the shift.

sysdeps/ieee754/dbl-64/s_setpayload_main.c

index 779371837cc1b9c467b1bf9bc3c71e6ca629d87f..2c6c946ae79b72da3b1d98fed2d86a8bc54f4c56 100644 (file)
@@ -37,7 +37,9 @@ FUNC (double *x, double payload)
      except for 0 when allowed; (c) not an integer.  */
   if (exponent >= BIAS + PAYLOAD_DIG
       || (exponent < BIAS && !(SET_HIGH_BIT && ix == 0))
-      || (ix & ((1ULL << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1)) != 0)
+      || ((BIAS + EXPLICIT_MANT_DIG - exponent) < 64
+         && (ix & ((1ULL << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1))
+         != 0))
     {
       INSERT_WORDS64 (*x, 0);
       return 1;