crypto/bio/bio_print.c: fix space padding calculation

Sign, prefix, and zero padding should count towards precision.

Signed-off-by: Eugene Syromiatnikov <esyr@openssl.org>

Reviewed-by: Saša Nedvědický <sashan@openssl.org>
Reviewed-by: Neil Horman <nhorman@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28177)
This commit is contained in:
Eugene Syromiatnikov 2025-08-05 15:19:12 +02:00 committed by Neil Horman
parent 95af148e14
commit badbcc6631
1 changed files with 3 additions and 3 deletions

View File

@ -500,16 +500,16 @@ fmtint(char **sbuffer,
* if necessary, to force the first digit of the result to be a zero
*/
zpadlen = max - place - (prefix == oct_prefix);
spadlen =
min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - (int)strlen(prefix);
if (zpadlen < 0)
zpadlen = 0;
spadlen =
min - OSSL_MAX(max, place + zpadlen + (signvalue ? 1 : 0) + (int)strlen(prefix));
if (spadlen < 0)
spadlen = 0;
if (flags & DP_F_MINUS) {
spadlen = -spadlen;
} else if (flags & DP_F_ZERO) {
zpadlen = OSSL_MAX(zpadlen, spadlen);
zpadlen = zpadlen + spadlen;
spadlen = 0;
}