Bug 1925204

Summary: glibc: printf of long double with a value of 0 results in "nan" [rhel-7.9.z]
Product: Red Hat Enterprise Linux 7 Reporter: Oran Agra <oran>
Component: glibcAssignee: glibc team <glibc-bugzilla>
Status: CLOSED ERRATA QA Contact: qe-baseos-tools-bugs
Severity: urgent Docs Contact:
Priority: urgent    
Version: 7.9CC: ashankar, ayadav, biholmes, brandfbb, brclark, codonell, dj, elgueromexicano, eric.wood, fweimer, jrd-rhbz, jreznik, juqiao, kahara, knweiss, mails.bugzilla.redhat.com, mnewsome, pasik, pasteur, paul.f.roberts.jr, pfrankli, rhel, sipoyare, skolosov, sreber, ziegleka
Target Milestone: rcKeywords: Triaged, ZStream
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: glibc-2.17-323.el7_9 Doc Type: Bug Fix
Doc Text:
Cause: The fix for CVE-2020-29573 resulted in a regression in the printf family of functions on i686 and x86_64 when printing zero in long double format. Consequence: The printf function would print "nan" for zero on i686 and x86_64. Fix: The logic to identify NaNs was updated to ensure that printf family of functions identify NaNs correctly. Result: The printf family of functions now print long double zero correctly.
Story Points: ---
Clone Of: Environment:
Last Closed: 2021-02-08 15:37:09 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Oran Agra 2021-02-04 15:19:03 UTC
Description of problem:
After a certain upgrade printf of long double with a value of 0, produces "nan"
(printing non-long doubles, or long double with value other than 0 seem fine)


Version-Release number of selected component (if applicable):


How reproducible:
easily reproducible.

Steps to Reproduce:
$ cat ld2str.c
#include <stdio.h>
void main() {
    long double d = 0;
    printf("%Lg\r\n",d);
    printf("%Lf\r\n",d);
}

$ gcc ld2str.c 
$ ./a.out 

Actual results:
nan
nan

Expected results:
0
0.000000

Additional info:
printf("glibc version: %s\n", gnu_get_libc_version());
glibc version: 2.17

$ rpm -q glibc
glibc-2.17-322.el7_9.x86_64


This started failing Redis's CI yesterday (only on CentOS):
https://github.com/redis/redis/runs/1827018214?check_suite_focus=true
so i suppose it's some glibc update that was rolled out by someone.

Comment 3 Matthias Hensler 2021-02-04 22:33:07 UTC
This bug seems to trigger some serious issues.

In my case the glibc-update resulted in a lot of failures in an asterisk-installation where a lot of conditionchecks in the dialplan suddenly returned "nan" instead of "0".

I had to downgrade via "yum downgrade glibc glibc-common glibc-devel glibc-headers" to 0:2.17-317.el7.

Comment 4 Siddhesh Poyarekar 2021-02-05 02:10:16 UTC
*** Bug 1925306 has been marked as a duplicate of this bug. ***

Comment 7 Carlos O'Donell 2021-02-05 04:09:22 UTC
(In reply to Oran Agra from comment #0)
> This started failing Redis's CI yesterday (only on CentOS):
> https://github.com/redis/redis/runs/1827018214?check_suite_focus=true
> so i suppose it's some glibc update that was rolled out by someone.

Thank you very much for this report.

This is related to the fix for CVE-2020-29573, where we made a change with limited scope to correct the security defect.

We are working to correct this issue as quickly as we can. Thank you for your patience.

Comment 19 Florian Weimer 2021-02-05 15:47:35 UTC
I've edited the description to mention the correct expected results, given that %f does not remove trailing zeros after the decimal point:

 Expected results:
 0
-0
+0.000000

Comment 20 Sergey Kolosov 2021-02-05 16:07:43 UTC
Verified, the reproducer returns 0 and 0.000000.

Comment 28 errata-xmlrpc 2021-02-08 15:37:09 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (glibc bug fix update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2021:0439