]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/bio/bio_print.c: fix space padding calculation
authorEugene Syromiatnikov <esyr@openssl.org>
Tue, 5 Aug 2025 13:19:12 +0000 (15:19 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 29 Aug 2025 16:18:30 +0000 (12:18 -0400)
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)

crypto/bio/bio_print.c

index 6f67a870b6511609d937f98c7c31f20af037d7c1..d08b37370faf461dd40e942c7f042901bf8a25e7 100644 (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;
     }