From: Bernd Edlinger Date: Thu, 24 Apr 2025 19:09:40 +0000 (+0200) Subject: Fix also BIO_printf formatting for INF and NAN X-Git-Tag: openssl-3.0.17~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83d8dba4bb8fe5fb8a9bba0be896d8fe38cb2705;p=thirdparty%2Fopenssl.git Fix also BIO_printf formatting for INF and NAN Avoid infinite loooooooops in %e and %g formatting for +/-INF and make the invalid value at least visible by using '?' as signvalue. Fixes #26973 Reviewed-by: Matt Caswell Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/27491) (cherry picked from commit b56dd5bfec8e790cc2d5b1bdca6ecd350a3b7779) --- diff --git a/crypto/bio/bio_print.c b/crypto/bio/bio_print.c index 254c7ab0441..19d2a613e9a 100644 --- a/crypto/bio/bio_print.c +++ b/crypto/bio/bio_print.c @@ -535,6 +535,10 @@ static LDOUBLE abs_val(LDOUBLE value) LDOUBLE result = value; if (value < 0) result = -value; + if (result > 0 && result / 2 == result) /* INF */ + result = 0; + else if (result != result) /* NAN */ + result = 0; return result; } @@ -591,6 +595,8 @@ fmtfp(char **sbuffer, else if (flags & DP_F_SPACE) signvalue = ' '; ufvalue = abs_val(fvalue); + if (ufvalue == 0 && fvalue != 0) /* INF or NAN? */ + signvalue = '?'; /* * G_FORMAT sometimes prints like E_FORMAT and sometimes like F_FORMAT