From: Eugene Syromiatnikov Date: Fri, 15 Aug 2025 14:28:11 +0000 (+0200) Subject: crypto/bio/bio_print.c: improve the precision handling in fmtint X-Git-Tag: openssl-3.6.0-alpha1~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ac492027221eefcd2f015a20d3a1fd2680882a9a;p=thirdparty%2Fopenssl.git crypto/bio/bio_print.c: improve the precision handling in fmtint Per [1]: * A negative precision is taken as if the precision were omitted. * The default precision is 1. * For d, i, o, u, x, and X conversion specifiers, if a precision is specified, the '0' flag shall be ignored. [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 5f2afdde4cd..e1f7ddc641d 100644 --- a/crypto/bio/bio_print.c +++ b/crypto/bio/bio_print.c @@ -528,8 +528,16 @@ fmtint(struct pr_desc *desc, int zpadlen = 0; int caps = 0; - if (max < 0) - max = 0; + if (max < 0) { + /* A negative precision is taken as if the precision were omitted. */ + max = 1; + } else { + /* + * If a precision is given with an integer conversion, + * the 0 flag is ignored. + */ + flags &= ~DP_F_ZERO; + } uvalue = value; if (!(flags & DP_F_UNSIGNED)) { if (value < 0) {