aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2025-04-21 15:12:21 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2025-04-25 17:46:05 -0300
commitb0ff367ead71a07b1facfdd3b6904de412aefca3 (patch)
tree39f5318eb8f4c3ec7ab810e7c72fb13cfa9d6538
parent9f158250432ef28e9953d18a6a63cc7b36feba5f (diff)
downloadglibc-b0ff367ead71a07b1facfdd3b6904de412aefca3.tar.xz
glibc-b0ff367ead71a07b1facfdd3b6904de412aefca3.zip
math: Fix UB in setayload
The code can shift the 1ULL for value larger than 63 depending of the exponent value. Add a check prior the shift.
-rw-r--r--sysdeps/ieee754/dbl-64/s_setpayload_main.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/sysdeps/ieee754/dbl-64/s_setpayload_main.c b/sysdeps/ieee754/dbl-64/s_setpayload_main.c
index 779371837c..2c6c946ae7 100644
--- a/sysdeps/ieee754/dbl-64/s_setpayload_main.c
+++ b/sysdeps/ieee754/dbl-64/s_setpayload_main.c
@@ -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;