Module Name: src
Committed By: christos
Date: Thu May 6 16:15:33 UTC 2021
Modified Files:
src/lib/libc/gdtoa: dtoa.c gdtoa.c strtoIg.c strtod.c strtodg.c
Log Message:
PR/56148: Andreas Gustafsson: lib/libc/stdio/t_printf:snprintf_float test
randomly fails.
Add checks to all places where lshift is called because it can return NULL
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libc/gdtoa/dtoa.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libc/gdtoa/gdtoa.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/gdtoa/strtoIg.c
cvs rdiff -u -r1.17 -r1.18 src/lib/libc/gdtoa/strtod.c
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/gdtoa/strtodg.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/gdtoa/dtoa.c
diff -u src/lib/libc/gdtoa/dtoa.c:1.10 src/lib/libc/gdtoa/dtoa.c:1.11
--- src/lib/libc/gdtoa/dtoa.c:1.10 Wed May 16 13:48:59 2012
+++ src/lib/libc/gdtoa/dtoa.c Thu May 6 12:15:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dtoa.c,v 1.10 2012/05/16 17:48:59 alnsn Exp $ */
+/* $NetBSD: dtoa.c,v 1.11 2021/05/06 16:15:33 christos Exp $ */
/****************************************************************
@@ -787,6 +787,8 @@ dtoa
}
#endif
b = lshift(b, 1);
+ if (b == NULL)
+ return NULL;
j = cmp(b, S);
#ifdef ROUND_BIASED
if (j >= 0)
Index: src/lib/libc/gdtoa/gdtoa.c
diff -u src/lib/libc/gdtoa/gdtoa.c:1.7 src/lib/libc/gdtoa/gdtoa.c:1.8
--- src/lib/libc/gdtoa/gdtoa.c:1.7 Wed Jul 31 22:27:43 2019
+++ src/lib/libc/gdtoa/gdtoa.c Thu May 6 12:15:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: gdtoa.c,v 1.7 2019/08/01 02:27:43 riastradh Exp $ */
+/* $NetBSD: gdtoa.c,v 1.8 2021/05/06 16:15:33 christos Exp $ */
/****************************************************************
@@ -601,10 +601,16 @@ gdtoa
*/
i = ((s5 ? hi0bits(S->x[S->wds-1]) : ULbits - 1) - s2 - 4) & kmask;
m2 += i;
- if ((b2 += i) > 0)
+ if ((b2 += i) > 0) {
b = lshift(b, b2);
- if ((s2 += i) > 0)
+ if (b == NULL)
+ return NULL;
+ }
+ if ((s2 += i) > 0) {
S = lshift(S, s2);
+ if (S == NULL)
+ return NULL;
+ }
if (k_check) {
if (cmp(b,S) < 0) {
k--;
Index: src/lib/libc/gdtoa/strtoIg.c
diff -u src/lib/libc/gdtoa/strtoIg.c:1.4 src/lib/libc/gdtoa/strtoIg.c:1.5
--- src/lib/libc/gdtoa/strtoIg.c:1.4 Wed Jul 31 22:27:43 2019
+++ src/lib/libc/gdtoa/strtoIg.c Thu May 6 12:15:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: strtoIg.c,v 1.4 2019/08/01 02:27:43 riastradh Exp $ */
+/* $NetBSD: strtoIg.c,v 1.5 2021/05/06 16:15:33 christos Exp $ */
/****************************************************************
@@ -119,6 +119,8 @@ strtoIg(CONST char *s00, char **se, CONS
}
else {
b1 = lshift(b1, 1);
+ if (b1 == NULL)
+ return STRTOG_NoMemory;
b1->x[0] |= 1;
--e1;
}
Index: src/lib/libc/gdtoa/strtod.c
diff -u src/lib/libc/gdtoa/strtod.c:1.17 src/lib/libc/gdtoa/strtod.c:1.18
--- src/lib/libc/gdtoa/strtod.c:1.17 Fri Sep 18 10:19:34 2020
+++ src/lib/libc/gdtoa/strtod.c Thu May 6 12:15:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: strtod.c,v 1.17 2020/09/18 14:19:34 christos Exp $ */
+/* $NetBSD: strtod.c,v 1.18 2021/05/06 16:15:33 christos Exp $ */
/****************************************************************
@@ -712,6 +712,8 @@ _int_strtod_l(CONST char *s00, char **se
#endif
{
delta = lshift(delta,Log2P);
+ if (delta == NULL)
+ goto ovfl;
if (cmp(delta, bs) <= 0)
dval(&adj) = -0.5;
}
@@ -804,6 +806,8 @@ _int_strtod_l(CONST char *s00, char **se
break;
}
delta = lshift(delta,Log2P);
+ if (delta == NULL)
+ goto ovfl;
if (cmp(delta, bs) > 0)
goto drop_down;
break;
Index: src/lib/libc/gdtoa/strtodg.c
diff -u src/lib/libc/gdtoa/strtodg.c:1.12 src/lib/libc/gdtoa/strtodg.c:1.13
--- src/lib/libc/gdtoa/strtodg.c:1.12 Fri Apr 19 06:41:53 2013
+++ src/lib/libc/gdtoa/strtodg.c Thu May 6 12:15:33 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: strtodg.c,v 1.12 2013/04/19 10:41:53 joerg Exp $ */
+/* $NetBSD: strtodg.c,v 1.13 2021/05/06 16:15:33 christos Exp $ */
/****************************************************************
@@ -248,8 +248,11 @@ rvOK
}
}
}
- else if (bdif < 0)
+ else if (bdif < 0) {
b = lshift(b, -bdif);
+ if (b == NULL)
+ return STRTOG_NoMemory;
+ }
if (e < fpi->emin) {
k = fpi->emin - e;
e = fpi->emin;
@@ -679,6 +682,8 @@ strtodg(CONST char *s00, char **se, CONS
j = rve - emin;
if (j > 0) {
rvb = lshift(rvb, j);
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
rvbits += j;
}
else if (j < 0) {
@@ -950,8 +955,11 @@ strtodg(CONST char *s00, char **se, CONS
return STRTOG_NoMemory;
if (abe < 0)
rshift(ab, -abe);
- else if (abe > 0)
+ else if (abe > 0) {
ab = lshift(ab, abe);
+ if (ab == NULL)
+ return STRTOG_NoMemory;
+ }
rvb0 = rvb;
if (asub) {
/* rv -= adj; */
@@ -1027,8 +1035,11 @@ strtodg(CONST char *s00, char **se, CONS
Bfree(delta);
}
if (!denorm && (j = nbits - rvbits)) {
- if (j > 0)
+ if (j > 0) {
rvb = lshift(rvb, j);
+ if (rvb == NULL)
+ return STRTOG_NoMemory;
+ }
else
rshift(rvb, -j);
rve -= j;