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

sysdeps/ieee754/flt-32/s_setpayloadf_main.c

index 700181c93aa19f17643bf7f474bc07d8bc3b6059..25cae87eff65eb8699bdc654f5d94f2421e5a685 100644 (file)
@@ -37,7 +37,8 @@ FUNC (float *x, float payload)
      except for 0 when allowed; (c) not an integer.  */
   if (exponent >= BIAS + PAYLOAD_DIG
       || (exponent < BIAS && !(SET_HIGH_BIT && ix == 0))
-      || (ix & ((1U << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1)) != 0)
+      || ((BIAS + EXPLICIT_MANT_DIG - exponent) < 32
+         && (ix & ((1U << (BIAS + EXPLICIT_MANT_DIG - exponent)) - 1)) != 0))
     {
       SET_FLOAT_WORD (*x, 0);
       return 1;