Skip to content

Commit a965937

Browse files
committed
Merge pull request #361
5d4c5a3 Prevent damage_array in the signature test from going out of bounds. (Gregory Maxwell)
2 parents 419bf7f + 5d4c5a3 commit a965937

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/tests.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3607,13 +3607,13 @@ static void assign_big_endian(unsigned char *ptr, size_t ptrlen, uint32_t val) {
36073607
static void damage_array(unsigned char *sig, size_t *len) {
36083608
int pos;
36093609
int action = secp256k1_rand_bits(3);
3610-
if (action < 1) {
3610+
if (action < 1 && *len > 3) {
36113611
/* Delete a byte. */
36123612
pos = secp256k1_rand_int(*len);
36133613
memmove(sig + pos, sig + pos + 1, *len - pos - 1);
36143614
(*len)--;
36153615
return;
3616-
} else if (action < 2) {
3616+
} else if (action < 2 && *len < 2048) {
36173617
/* Insert a byte. */
36183618
pos = secp256k1_rand_int(1 + *len);
36193619
memmove(sig + pos + 1, sig + pos, *len - pos);
@@ -3785,6 +3785,7 @@ void run_ecdsa_der_parse(void) {
37853785
int certainly_der = 0;
37863786
int certainly_not_der = 0;
37873787
random_ber_signature(buffer, &buflen, &certainly_der, &certainly_not_der);
3788+
CHECK(buflen <= 2048);
37883789
for (j = 0; j < 16; j++) {
37893790
int ret = 0;
37903791
if (j > 0) {

0 commit comments

Comments
 (0)