From fe6615b31de428c80ca23ba997a5640a41bca237 Mon Sep 17 00:00:00 2001 From: rhe Date: Thu, 2 Nov 2017 06:30:18 +0000 Subject: [PATCH] bignum.c: avoid use of uninitialized value in Integer.sqrt This is a follow-up fix to r57713. estimate_initial_sqrt() didn't initialize BDIGITs except the topmost two, letting Integer.sqrt return wrong result in the fast path, such as for (1<<504). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60611 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 1 + 1 file changed, 1 insertion(+) diff --git a/bignum.c b/bignum.c index 361a12fb19..47b5f57d49 100644 --- a/bignum.c +++ b/bignum.c @@ -6830,6 +6830,7 @@ estimate_initial_sqrt(VALUE *xp, const size_t xn, const BDIGIT *nds, size_t len) if (rshift >= 0) { d <<= rshift; } + BDIGITS_ZERO(xds, xn-2); bdigitdbl2bary(&xds[xn-2], 2, d); if (!lowbits) return NULL; /* special case, exact result */