From: Eugene Syromiatnikov Date: Fri, 15 Aug 2025 14:35:11 +0000 (+0200) Subject: crypto/bio/bio_print.c: handle the case of 0 with zero precision X-Git-Tag: openssl-3.6.0-alpha1~30 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c5e3e7bfb678a847e509f73432da82745e03fd31;p=thirdparty%2Fopenssl.git crypto/bio/bio_print.c: handle the case of 0 with zero precision 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 Reviewed-by: Saša Nedvědický Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/28177) --- diff --git a/crypto/bio/bio_print.c b/crypto/bio/bio_print.c index e1f7ddc641d..7a2b2fae548 100644 --- a/crypto/bio/bio_print.c +++ b/crypto/bio/bio_print.c @@ -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;