Commit c576d35a85 for openssl.org
commit c576d35a85d9fbd8d84b9d0a0e75afd7eeb8c6b5
Author: Paul Dale <paul.dale@oracle.com>
Date: Mon Nov 23 13:00:30 2026 +1100
include/internal/safe_math.h: allow minimum signed products in the portable helper
Accept a negative product equal to the signed minimum when neither
factor is one. After the positive-limit check fails, equality
with the minimum quotient identifies the additional representable
product.
Fixes: b037e3637a49 "header: add integer overflow helper functions"
Link: https://github.com/openssl/openssl/pull/33891
Co-Authored-by: Juan C <juanconrod@protonmail.com>
Assisted-by: ChatGPT:gpt-6-Sol
Reviewed-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Merge-date: Tue Nov 24 18:13:16 2026
Merged-from: https://github.com/openssl/openssl/pull/33917
diff --git a/include/internal/safe_math.h b/include/internal/safe_math.h
index b24502803f..d2702dbb31 100644
--- a/include/internal/safe_math.h
+++ b/include/internal/safe_math.h
@@ -175,6 +175,9 @@
\
if (x <= max / y) \
return a * b; \
+ /* A negative product can also equal the minimum. */ \
+ if (((a < 0) ^ (b < 0)) && -x == min / y) \
+ return min; \
} \
*err |= 1; \
return (a < 0) ^ (b < 0) ? min : max; \