Bug 22243

Summary: log2(0) and log10(0) are wrong in downward rounding without the svid compat wrapper
Product: glibc Reporter: Szabolcs Nagy <nszabolcs>
Component: mathAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal Flags: fweimer: security-
Priority: P2    
Version: 2.27   
Target Milestone: 2.27   
Host: Target:
Build: Last reconfirmed:

Description Szabolcs Nagy 2017-10-03 16:03:13 UTC
log2(0) and log10(0) return inf instead of -inf in downward rounding when the svid wrapper is suppressed (static linking, new targets).

#include <math.h>
#include <stdio.h>
#include <fenv.h>

int main()
{
	fesetround(FE_DOWNWARD);
	double y1 = log2(0);
	double y2 = log10(0);
	fesetround(FE_TONEAREST);
	printf("%a\n", y1);
	printf("%a\n", y2);
}

prints

inf
inf

with static linking.
Comment 1 Szabolcs Nagy 2017-10-03 16:14:05 UTC
wordsize-64 targets only
Comment 2 Sourceware Commits 2017-10-04 09:16:33 UTC
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, master has been updated
       via  86c27ade1e44e29922d33676f950f7334edb37a7 (commit)
       via  8f8f8ef7aba40ef883291e4c4d95a419c3327d70 (commit)
      from  955774751b71c4bc94029dd541ad9d34634ec995 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=86c27ade1e44e29922d33676f950f7334edb37a7

commit 86c27ade1e44e29922d33676f950f7334edb37a7
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Tue Oct 3 18:12:42 2017 +0100

    [BZ #22244] Fix yn(n,0) without SVID wrapper
    
    Without SVID compat wrapper yn(n,0) and ynf(n,0) does not raise
    the divide-by-zero excpetion and it may return inf with the wrong
    sign for n < 0.
    
    	[BZ #22244]
    	* sysdeps/ieee754/dbl-64/e_jn.c (__ieee754_yn): Fix x == 0 case.
    	* sysdeps/ieee754/flt-32/e_jnf.c (__ieee754_ynf): Likewise.

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=8f8f8ef7aba40ef883291e4c4d95a419c3327d70

commit 8f8f8ef7aba40ef883291e4c4d95a419c3327d70
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Tue Oct 3 17:13:18 2017 +0100

    [BZ #22243] fix log2(0) and log(10) in downward rounding
    
    On 64bit targets if the SVID compat wrapper is suppressed (e.g. static linking)
    then log2(0) and log10(0) returned inf instead of -inf.
    
    	[BZ #22243]
    	* sysdeps/ieee754/dbl-64/wordsize-64/e_log10.c (__ieee754_log10): Use fabs.
    	* sysdeps/ieee754/dbl-64/wordsize-64/e_log2.c (__ieee754_log2): Likewise.

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                                    |   12 ++++++++++++
 sysdeps/ieee754/dbl-64/e_jn.c                |   10 +++++-----
 sysdeps/ieee754/dbl-64/wordsize-64/e_log10.c |    2 +-
 sysdeps/ieee754/dbl-64/wordsize-64/e_log2.c  |    2 +-
 sysdeps/ieee754/flt-32/e_jnf.c               |    6 +++---
 5 files changed, 22 insertions(+), 10 deletions(-)
Comment 3 Szabolcs Nagy 2017-10-04 09:33:28 UTC
fixed.