diff options
author | jsing <> | 2022-08-28 17:59:57 +0000 |
---|---|---|
committer | jsing <> | 2022-08-28 17:59:57 +0000 |
commit | 83a91122b8be089cdc00d8850c82849d496b8207 (patch) | |
tree | cc91c2b3e3a8058c311f56920abdeba9975a087b /src | |
parent | fc40a94c1070698fc2309e20e5f331b5152f85b5 (diff) | |
download | openbsd-83a91122b8be089cdc00d8850c82849d496b8207.tar.gz openbsd-83a91122b8be089cdc00d8850c82849d496b8207.tar.bz2 openbsd-83a91122b8be089cdc00d8850c82849d496b8207.zip |
Add regress test for the encoding of an ASN1_INTEGER with NULL data.
Diffstat (limited to 'src')
-rw-r--r-- | src/regress/lib/libcrypto/asn1/asn1basic.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/src/regress/lib/libcrypto/asn1/asn1basic.c b/src/regress/lib/libcrypto/asn1/asn1basic.c index f3b768407d..9ab23e7849 100644 --- a/src/regress/lib/libcrypto/asn1/asn1basic.c +++ b/src/regress/lib/libcrypto/asn1/asn1basic.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: asn1basic.c,v 1.9 2022/06/25 15:49:28 jsing Exp $ */ | 1 | /* $OpenBSD: asn1basic.c,v 1.10 2022/08/28 17:59:57 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> | 3 | * Copyright (c) 2017, 2021 Joel Sing <jsing@openbsd.org> |
4 | * | 4 | * |
@@ -678,6 +678,42 @@ asn1_integer_cmp_test(void) | |||
678 | } | 678 | } |
679 | 679 | ||
680 | static int | 680 | static int |
681 | asn1_integer_null_data_test(void) | ||
682 | { | ||
683 | const uint8_t der[] = {0x02, 0x01, 0x00}; | ||
684 | ASN1_INTEGER *aint = NULL; | ||
685 | uint8_t *p = NULL, *pp; | ||
686 | int len; | ||
687 | int failed = 0; | ||
688 | |||
689 | if ((aint = ASN1_INTEGER_new()) == NULL) { | ||
690 | fprintf(stderr, "FAIL: ASN1_INTEGER_new() == NULL\n"); | ||
691 | goto failed; | ||
692 | } | ||
693 | if ((len = i2d_ASN1_INTEGER(aint, NULL)) < 0) { | ||
694 | fprintf(stderr, "FAIL: i2d_ASN1_INTEGER() failed\n"); | ||
695 | goto failed; | ||
696 | } | ||
697 | if ((p = calloc(1, len)) == NULL) | ||
698 | errx(1, "calloc"); | ||
699 | pp = p; | ||
700 | if ((len = i2d_ASN1_INTEGER(aint, &pp)) < 0) { | ||
701 | fprintf(stderr, "FAIL: i2d_ASN1_INTEGER() failed\n"); | ||
702 | goto failed; | ||
703 | } | ||
704 | if (!asn1_compare_bytes("INTEGER NULL data", p, len, der, sizeof(der))) | ||
705 | goto failed; | ||
706 | |||
707 | failed = 0; | ||
708 | |||
709 | failed: | ||
710 | ASN1_INTEGER_free(aint); | ||
711 | free(p); | ||
712 | |||
713 | return failed; | ||
714 | } | ||
715 | |||
716 | static int | ||
681 | asn1_integer_test(void) | 717 | asn1_integer_test(void) |
682 | { | 718 | { |
683 | struct asn1_integer_test *ait; | 719 | struct asn1_integer_test *ait; |
@@ -694,6 +730,7 @@ asn1_integer_test(void) | |||
694 | } | 730 | } |
695 | 731 | ||
696 | failed |= asn1_integer_cmp_test(); | 732 | failed |= asn1_integer_cmp_test(); |
733 | failed |= asn1_integer_null_data_test(); | ||
697 | failed |= asn1_integer_set_val_test(); | 734 | failed |= asn1_integer_set_val_test(); |
698 | 735 | ||
699 | return failed; | 736 | return failed; |