In a highly unlikely situation of str being longer than INT_MAX,
a signed integer overflow in padlen calculation can be triggered.
Avoid it by reworking the check for the need of padlen calculation.
Fixes: 230c691a5218 "Fix fmtstr for BIO_printf() et al"
Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28502)
strln = OPENSSL_strnlen(value, max < 0 ? SIZE_MAX : (size_t)max);
- padlen = (int)(min - strln);
- if (min < 0 || padlen < 0)
- padlen = 0;
+ if (min >= 0 && strln < INT_MAX) {
+ padlen = min - (int)strln;
+ if (padlen < 0)
+ padlen = 0;
+ }
if (max >= 0) {
/*
* Calculate the maximum output including padding.