提交 f3cf2251 编写于 作者: K Kurt Roeckx

Avoid creating illegal pointers

Found by tis-interpreter
Reviewed-by: NRich Salz <rsalz@openssl.org>

GH: #1179
上级 0a320653
...@@ -565,9 +565,9 @@ BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret) ...@@ -565,9 +565,9 @@ BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)
if (ret == NULL) if (ret == NULL)
return (NULL); return (NULL);
bn_check_top(ret); bn_check_top(ret);
s += len - 1; s += len;
/* Skip trailing zeroes. */ /* Skip trailing zeroes. */
for ( ; len > 0 && *s == 0; s--, len--) for ( ; len > 0 && s[-1] == 0; s--, len--)
continue; continue;
n = len; n = len;
if (n == 0) { if (n == 0) {
...@@ -584,7 +584,8 @@ BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret) ...@@ -584,7 +584,8 @@ BIGNUM *BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)
ret->neg = 0; ret->neg = 0;
l = 0; l = 0;
while (n--) { while (n--) {
l = (l << 8L) | *(s--); s--;
l = (l << 8L) | *s;
if (m-- == 0) { if (m-- == 0) {
ret->d[--i] = l; ret->d[--i] = l;
l = 0; l = 0;
...@@ -610,10 +611,11 @@ int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen) ...@@ -610,10 +611,11 @@ int BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen)
/* Add trailing zeroes if necessary */ /* Add trailing zeroes if necessary */
if (tolen > i) if (tolen > i)
memset(to + i, 0, tolen - i); memset(to + i, 0, tolen - i);
to += i - 1; to += i;
while (i--) { while (i--) {
l = a->d[i / BN_BYTES]; l = a->d[i / BN_BYTES];
*(to--) = (unsigned char)(l >> (8 * (i % BN_BYTES))) & 0xff; to--;
*to = (unsigned char)(l >> (8 * (i % BN_BYTES))) & 0xff;
} }
return tolen; return tolen;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册