diff options
| author | tb <> | 2026-08-30 16:55:41 +0000 |
|---|---|---|
| committer | tb <> | 2026-08-30 16:55:41 +0000 |
| commit | c21f3ed15976421f8bfd125da34f3b15fbeb05e7 (patch) | |
| tree | 6874c42fd42fba1cac4de6d0ca60b5d79230864d /src | |
| parent | 88ac71e0f8273324409f56626c4c20b5473e8b58 (diff) | |
| download | openbsd-c21f3ed15976421f8bfd125da34f3b15fbeb05e7.tar.gz openbsd-c21f3ed15976421f8bfd125da34f3b15fbeb05e7.tar.bz2 openbsd-c21f3ed15976421f8bfd125da34f3b15fbeb05e7.zip | |
Add test case causing an OOB access in PKCS7_stream
Test case originally from openssl/openssl#31681, exercised via a direct
call to PKCS7_stream() as in a report from Acts1631.
To be fixed in pk7_lib.c r1.33
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/pkcs7/pkcs7test.c | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/pkcs7/pkcs7test.c b/src/regress/lib/libcrypto/pkcs7/pkcs7test.c index ae7c41299b..6a3bcce3d1 100644 --- a/src/regress/lib/libcrypto/pkcs7/pkcs7test.c +++ b/src/regress/lib/libcrypto/pkcs7/pkcs7test.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: pkcs7test.c,v 1.7 2026/08/30 16:52:07 tb Exp $ */ | 1 | /* $OpenBSD: pkcs7test.c,v 1.8 2026/08/30 16:55:41 tb Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> |
| 4 | * Copyright (c) 2026 Theo Buehler <tb@openbsd.org> | 4 | * Copyright (c) 2026 Theo Buehler <tb@openbsd.org> |
| @@ -399,6 +399,65 @@ pkcs7_stream_missing_content(void) | |||
| 399 | return failed; | 399 | return failed; |
| 400 | } | 400 | } |
| 401 | 401 | ||
| 402 | /* | ||
| 403 | * SEQUENCE { | ||
| 404 | * # signedData | ||
| 405 | * OBJECT_IDENTIFIER { 1.2.840.113549.1.7.2 } | ||
| 406 | * [0] { | ||
| 407 | * SEQUENCE { | ||
| 408 | * INTEGER { 1 } | ||
| 409 | * SET {} | ||
| 410 | * SEQUENCE { | ||
| 411 | * # id-ct-TSTInfo | ||
| 412 | * OBJECT_IDENTIFIER { 1.2.840.113549.1.9.16.1.4 } | ||
| 413 | * [0] { | ||
| 414 | * SEQUENCE { | ||
| 415 | * INTEGER { 1 } | ||
| 416 | * OCTET_STRING { `deadbeef` } | ||
| 417 | * } | ||
| 418 | * } | ||
| 419 | * } | ||
| 420 | * SET {} | ||
| 421 | * } | ||
| 422 | * } | ||
| 423 | * } | ||
| 424 | */ | ||
| 425 | static const uint8_t pkcs7_malformed_der[] = { | ||
| 426 | 0x30, 0x32, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, | ||
| 427 | 0xf7, 0x0d, 0x01, 0x07, 0x02, 0xa0, 0x25, 0x30, | ||
| 428 | 0x23, 0x02, 0x01, 0x01, 0x31, 0x00, 0x30, 0x1a, | ||
| 429 | 0x06, 0x0b, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, | ||
| 430 | 0x01, 0x09, 0x10, 0x01, 0x04, 0xa0, 0x0b, 0x30, | ||
| 431 | 0x09, 0x02, 0x01, 0x01, 0x04, 0x04, 0xde, 0xad, | ||
| 432 | 0xbe, 0xef, 0x31, 0x00, | ||
| 433 | }; | ||
| 434 | static int pkcs7_malformed_der_len = sizeof(pkcs7_malformed_der); | ||
| 435 | |||
| 436 | static int | ||
| 437 | pkcs7_stream_signedData_oob(void) | ||
| 438 | { | ||
| 439 | PKCS7 *p7 = NULL; | ||
| 440 | const unsigned char *p; | ||
| 441 | unsigned char **boundary = NULL; | ||
| 442 | int ret; | ||
| 443 | int failed = 1; | ||
| 444 | |||
| 445 | p = pkcs7_malformed_der; | ||
| 446 | if ((p7 = d2i_PKCS7(NULL, &p, pkcs7_malformed_der_len)) == NULL) | ||
| 447 | fatal("d2i_PKCS7 malformed"); | ||
| 448 | |||
| 449 | if ((ret = PKCS7_stream(&boundary, p7)) != 0) { | ||
| 450 | fprintf(stderr, "FAILURE: PKCS7_stream want 0, got %d\n", ret); | ||
| 451 | goto out; | ||
| 452 | } | ||
| 453 | |||
| 454 | failed = 0; | ||
| 455 | out: | ||
| 456 | PKCS7_free(p7); | ||
| 457 | |||
| 458 | return failed; | ||
| 459 | } | ||
| 460 | |||
| 402 | int | 461 | int |
| 403 | main(int argc, char **argv) | 462 | main(int argc, char **argv) |
| 404 | { | 463 | { |
| @@ -406,6 +465,7 @@ main(int argc, char **argv) | |||
| 406 | 465 | ||
| 407 | failed |= pkcs7_basics(); | 466 | failed |= pkcs7_basics(); |
| 408 | failed |= pkcs7_stream_missing_content(); | 467 | failed |= pkcs7_stream_missing_content(); |
| 468 | failed |= pkcs7_stream_signedData_oob(); | ||
| 409 | 469 | ||
| 410 | return failed; | 470 | return failed; |
| 411 | } | 471 | } |
