* bignum.c (bigxor_int): Fix a buffer over read.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-06-26 03:49:45 +00:00
Родитель 9be51267b5
Коммит 1457ee2ce4
2 изменённых файлов: 21 добавлений и 10 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Wed Jun 26 12:48:22 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bigxor_int): Fix a buffer over read.
Wed Jun 26 12:13:12 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bigand_int): Consider negative values.

Просмотреть файл

@ -4873,6 +4873,10 @@ bigxor_int(VALUE x, long y)
sign = (y >= 0) ? 1 : 0;
xds = BDIGITS(x);
zn = xn = RBIGNUM_LEN(x);
#if SIZEOF_BDIGITS < SIZEOF_LONG
if (zn < bdigit_roomof(SIZEOF_LONG))
zn = bdigit_roomof(SIZEOF_LONG);
#endif
z = bignew(zn, !(RBIGNUM_SIGN(x) ^ sign));
zds = BDIGITS(z);
@ -4880,19 +4884,22 @@ bigxor_int(VALUE x, long y)
i = 1;
zds[0] = xds[0] ^ y;
#else
{
long num = y;
for (i=0; i<bdigit_roomof(SIZEOF_LONG); i++) {
zds[i] = xds[i] ^ BIGLO(num);
num = BIGDN(num);
}
for (i = 0; i < xn; i++) {
zds[i] = xds[i] ^ BIGLO(y);
y = BIGDN(y);
}
for (; i < zn; i++) {
zds[i] = (RBIGNUM_SIGN(x) ? 0 : BDIGMAX) ^ BIGLO(y);
y = BIGDN(y);
}
#endif
while (i < xn) {
zds[i] = sign?xds[i]:BIGLO(~xds[i]);
i++;
for (; i < xn; i++) {
zds[i] = sign ? xds[i] : BIGLO(~xds[i]);
}
for (; i < zn; i++) {
zds[i] = sign ^ RBIGNUM_SIGN(x) ? BDIGMAX : 0;
}
if (!RBIGNUM_SIGN(z)) get2comp(z);
return bignorm(z);
}