diff options
| author | tb <> | 2022-03-30 08:57:26 +0000 |
|---|---|---|
| committer | tb <> | 2022-03-30 08:57:26 +0000 |
| commit | 92e12841ca3f8018421fe2f29d31573c6e2a477f (patch) | |
| tree | 50df512342a65eeb9a98c0a97841646f7d0b2279 /src | |
| parent | c650ef2b4f969ce6b8d9a39f9e86c5e181dfafbc (diff) | |
| download | openbsd-92e12841ca3f8018421fe2f29d31573c6e2a477f.tar.gz openbsd-92e12841ca3f8018421fe2f29d31573c6e2a477f.tar.bz2 openbsd-92e12841ca3f8018421fe2f29d31573c6e2a477f.zip | |
Add a simple test to ensure that pmeth->cleanup() can cope with NULL
pkey_ctx->data.
Diffstat (limited to 'src')
| -rw-r--r-- | src/regress/lib/libcrypto/evp/Makefile | 9 | ||||
| -rw-r--r-- | src/regress/lib/libcrypto/evp/evp_pkey_cleanup.c | 86 |
2 files changed, 93 insertions, 2 deletions
diff --git a/src/regress/lib/libcrypto/evp/Makefile b/src/regress/lib/libcrypto/evp/Makefile index 5abec99a98..f883584a17 100644 --- a/src/regress/lib/libcrypto/evp/Makefile +++ b/src/regress/lib/libcrypto/evp/Makefile | |||
| @@ -1,13 +1,15 @@ | |||
| 1 | # $OpenBSD: Makefile,v 1.6 2022/01/14 09:38:50 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.7 2022/03/30 08:57:26 tb Exp $ |
| 2 | 2 | ||
| 3 | PROGS= evptest evp_pkey_check | 3 | PROGS= evptest evp_pkey_check evp_pkey_cleanup |
| 4 | LDADD= -lcrypto | 4 | LDADD= -lcrypto |
| 5 | DPADD= ${LIBCRYPTO} | 5 | DPADD= ${LIBCRYPTO} |
| 6 | WARNINGS= Yes | 6 | WARNINGS= Yes |
| 7 | CFLAGS+= -DLIBRESSL_INTERNAL -DLIBRESSL_CRYPTO_INTERNAL -Werror | 7 | CFLAGS+= -DLIBRESSL_INTERNAL -DLIBRESSL_CRYPTO_INTERNAL -Werror |
| 8 | CFLAGS+= -I${.CURDIR}/../../../../lib/libcrypto/evp | ||
| 8 | 9 | ||
| 9 | REGRESS_TARGETS+= regress-evptest | 10 | REGRESS_TARGETS+= regress-evptest |
| 10 | REGRESS_TARGETS+= regress-evp_pkey_check | 11 | REGRESS_TARGETS+= regress-evp_pkey_check |
| 12 | REGRESS_TARGETS+= regress-evp_pkey_cleanup | ||
| 11 | 13 | ||
| 12 | regress-evptest: evptest | 14 | regress-evptest: evptest |
| 13 | ./evptest ${.CURDIR}/evptests.txt | 15 | ./evptest ${.CURDIR}/evptests.txt |
| @@ -15,4 +17,7 @@ regress-evptest: evptest | |||
| 15 | regress-evp_pkey_check: evp_pkey_check | 17 | regress-evp_pkey_check: evp_pkey_check |
| 16 | ./evp_pkey_check | 18 | ./evp_pkey_check |
| 17 | 19 | ||
| 20 | regress-evp_pkey_cleanup: evp_pkey_cleanup | ||
| 21 | ./evp_pkey_cleanup | ||
| 22 | |||
| 18 | .include <bsd.regress.mk> | 23 | .include <bsd.regress.mk> |
diff --git a/src/regress/lib/libcrypto/evp/evp_pkey_cleanup.c b/src/regress/lib/libcrypto/evp/evp_pkey_cleanup.c new file mode 100644 index 0000000000..5f8cc20d74 --- /dev/null +++ b/src/regress/lib/libcrypto/evp/evp_pkey_cleanup.c | |||
| @@ -0,0 +1,86 @@ | |||
| 1 | /* $OpenBSD: evp_pkey_cleanup.c,v 1.1 2022/03/30 08:57:26 tb Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 2022 Theo Buehler <tb@openbsd.org> | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 15 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 16 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <stdio.h> | ||
| 20 | |||
| 21 | #include <openssl/evp.h> | ||
| 22 | |||
| 23 | #include "evp_locl.h" | ||
| 24 | |||
| 25 | struct pkey_cleanup_test { | ||
| 26 | const char *name; | ||
| 27 | int nid; | ||
| 28 | void (*free)(void); | ||
| 29 | }; | ||
| 30 | |||
| 31 | int pkey_ids[] = { | ||
| 32 | EVP_PKEY_CMAC, | ||
| 33 | EVP_PKEY_DH, | ||
| 34 | EVP_PKEY_DSA, | ||
| 35 | EVP_PKEY_EC, | ||
| 36 | EVP_PKEY_GOSTIMIT, | ||
| 37 | EVP_PKEY_GOSTR01, | ||
| 38 | EVP_PKEY_HMAC, | ||
| 39 | EVP_PKEY_RSA, | ||
| 40 | EVP_PKEY_RSA_PSS, | ||
| 41 | }; | ||
| 42 | |||
| 43 | static const size_t N_PKEY_IDS = sizeof(pkey_ids) / sizeof(pkey_ids[0]); | ||
| 44 | |||
| 45 | static int | ||
| 46 | test_evp_pkey_ctx_cleanup(int nid) | ||
| 47 | { | ||
| 48 | EVP_PKEY_CTX *pkey_ctx = NULL; | ||
| 49 | void *data; | ||
| 50 | int failed = 1; | ||
| 51 | |||
| 52 | if ((pkey_ctx = EVP_PKEY_CTX_new_id(nid, NULL)) == NULL) { | ||
| 53 | fprintf(stderr, "EVP_PKEY_CTX_new_id(%d, NULL) failed\n", nid); | ||
| 54 | goto err; | ||
| 55 | } | ||
| 56 | |||
| 57 | data = EVP_PKEY_CTX_get_data(pkey_ctx); | ||
| 58 | |||
| 59 | EVP_PKEY_CTX_set_data(pkey_ctx, NULL); | ||
| 60 | if (pkey_ctx->pmeth->cleanup != NULL) | ||
| 61 | pkey_ctx->pmeth->cleanup(pkey_ctx); | ||
| 62 | |||
| 63 | EVP_PKEY_CTX_set_data(pkey_ctx, data); | ||
| 64 | |||
| 65 | failed = 0; | ||
| 66 | |||
| 67 | err: | ||
| 68 | EVP_PKEY_CTX_free(pkey_ctx); | ||
| 69 | |||
| 70 | return failed; | ||
| 71 | } | ||
| 72 | |||
| 73 | int | ||
| 74 | main(void) | ||
| 75 | { | ||
| 76 | size_t i; | ||
| 77 | int failed = 0; | ||
| 78 | |||
| 79 | for (i = 0; i < N_PKEY_IDS; i++) | ||
| 80 | failed |= test_evp_pkey_ctx_cleanup(pkey_ids[i]); | ||
| 81 | |||
| 82 | if (!failed) | ||
| 83 | printf("SUCCESS\n"); | ||
| 84 | |||
| 85 | return failed; | ||
| 86 | } | ||
