]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
crypto/bio/bio_print.c: handle the case of 0 with zero precision
authorEugene Syromiatnikov <esyr@openssl.org>
Fri, 15 Aug 2025 14:35:11 +0000 (16:35 +0200)
committerNeil Horman <nhorman@openssl.org>
Fri, 29 Aug 2025 16:18:30 +0000 (12:18 -0400)
Per [1]:

    The result of converting zero with an explicit precision of zero
    shall be no characters.

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/printf.html

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 e1f7ddc641db51d33fe0325ed5bc9e0bdeb8f2e6..7a2b2fae548b7089cb9b247ae01b3eb84ef0cc7d 100644 (file)
@@ -549,20 +549,21 @@ fmtint(struct pr_desc *desc,
             signvalue = ' ';
     }
     if (flags & DP_F_NUM) {
+        if (base == 8)
+            prefix = oct_prefix;
         if (value != 0) {
-            if (base == 8)
-                prefix = oct_prefix;
             if (base == 16)
                 prefix = flags & DP_F_UP ? "0X" : "0x";
         }
     }
     if (flags & DP_F_UP)
         caps = 1;
-    do {
+    /* When 0 is printed with an explicit precision 0, the output is empty. */
+    while (uvalue && (place < (int)sizeof(convert))) {
         convert[place++] = (caps ? "0123456789ABCDEF" : "0123456789abcdef")
             [uvalue % (unsigned)base];
         uvalue = (uvalue / (unsigned)base);
-    } while (uvalue && (place < (int)sizeof(convert)));
+    }
     if (place == sizeof(convert))
         place--;
     convert[place] = 0;