aboutsummaryrefslogtreecommitdiff
path: root/lib/hcrypto/bn.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/hcrypto/bn.c')
-rw-r--r--lib/hcrypto/bn.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/hcrypto/bn.c b/lib/hcrypto/bn.c
index e7d5b0473716..91933c0a2943 100644
--- a/lib/hcrypto/bn.c
+++ b/lib/hcrypto/bn.c
@@ -142,7 +142,8 @@ BN_bin2bn(const void *s, int len, BIGNUM *bn)
return NULL;
}
hi->length = len;
- memcpy(hi->data, s, len);
+ if (len)
+ memcpy(hi->data, s, len);
return (BIGNUM *)hi;
}
@@ -237,7 +238,7 @@ BN_is_bit_set(const BIGNUM *bn, int bit)
heim_integer *hi = (heim_integer *)bn;
unsigned char *p = hi->data;
- if ((bit / 8) > hi->length || hi->length == 0)
+ if ((bit / 8) >= hi->length || hi->length == 0)
return 0;
return p[hi->length - 1 - (bit / 8)] & is_set[bit % 8];
@@ -250,7 +251,7 @@ BN_set_bit(BIGNUM *bn, int bit)
unsigned char *p;
if ((bit / 8) > hi->length || hi->length == 0) {
- size_t len = (bit + 7) / 8;
+ size_t len = bit == 0 ? 1 : (bit + 7) / 8;
void *d = realloc(hi->data, len);
if (d == NULL)
return 0;