summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-08-31 09:33:39 +0000
committertb <>2022-08-31 09:33:39 +0000
commit835cf9363dd7d1a2a49eb5db9ccc62acdb54e089 (patch)
treefef18cbbf7f4eca2f4170d0c6b5d63cd06d109b0
parent1af840db6160c4511f1e225122056a69d23d80cd (diff)
downloadopenbsd-835cf9363dd7d1a2a49eb5db9ccc62acdb54e089.tar.gz
openbsd-835cf9363dd7d1a2a49eb5db9ccc62acdb54e089.tar.bz2
openbsd-835cf9363dd7d1a2a49eb5db9ccc62acdb54e089.zip
Avoid some buffer overflows in ecdsatest
The ASN.1 encoding of the modified ECDSA signature can grow in size due to padding of the ASN.1 integers. Instead of reusing the same signature buffer freshly allocate it. Avoids some buffer overflows caught by ASAN.
-rw-r--r--src/regress/lib/libcrypto/ecdsa/ecdsatest.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/regress/lib/libcrypto/ecdsa/ecdsatest.c b/src/regress/lib/libcrypto/ecdsa/ecdsatest.c
index 683260aeee..5e2419a91f 100644
--- a/src/regress/lib/libcrypto/ecdsa/ecdsatest.c
+++ b/src/regress/lib/libcrypto/ecdsa/ecdsatest.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecdsatest.c,v 1.9 2022/03/31 09:36:09 tb Exp $ */ 1/* $OpenBSD: ecdsatest.c,v 1.10 2022/08/31 09:33:39 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project. 3 * Written by Nils Larsch for the OpenSSL project.
4 */ 4 */
@@ -251,7 +251,8 @@ test_builtin(BIO *out)
251 BIO_printf(out, "."); 251 BIO_printf(out, ".");
252 (void)BIO_flush(out); 252 (void)BIO_flush(out);
253 /* create signature */ 253 /* create signature */
254 sig_len = ECDSA_size(eckey); 254 if ((sig_len = ECDSA_size(eckey)) == 0)
255 goto builtin_err;
255 if ((signature = malloc(sig_len)) == NULL) 256 if ((signature = malloc(sig_len)) == NULL)
256 goto builtin_err; 257 goto builtin_err;
257 if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey)) { 258 if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey)) {
@@ -332,8 +333,13 @@ test_builtin(BIO *out)
332 r = NULL; 333 r = NULL;
333 s = NULL; 334 s = NULL;
334 335
336 free(signature);
337 signature = NULL;
338
335 sig_ptr2 = signature; 339 sig_ptr2 = signature;
336 sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); 340 if ((sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2)) <= 0)
341 goto builtin_err;
342
337 if (ECDSA_verify(0, digest, 20, signature, sig_len, 343 if (ECDSA_verify(0, digest, 20, signature, sig_len,
338 eckey) == 1) { 344 eckey) == 1) {
339 BIO_printf(out, " failed\n"); 345 BIO_printf(out, " failed\n");
@@ -349,8 +355,12 @@ test_builtin(BIO *out)
349 r = NULL; 355 r = NULL;
350 s = NULL; 356 s = NULL;
351 357
358 free(signature);
359 signature = NULL;
360
352 sig_ptr2 = signature; 361 sig_ptr2 = signature;
353 sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); 362 if ((sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2)) <= 0)
363 goto builtin_err;
354 if (ECDSA_verify(0, digest, 20, signature, sig_len, 364 if (ECDSA_verify(0, digest, 20, signature, sig_len,
355 eckey) != 1) { 365 eckey) != 1) {
356 BIO_printf(out, " failed\n"); 366 BIO_printf(out, " failed\n");