diff options
author | Bernd Edlinger <bernd.edlinger@hotmail.de> | 2017-03-19 16:14:33 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2017-03-20 13:11:31 +0100 |
commit | b3c31a6572bd7b89f469deb3c78f85f6e303df47 (patch) | |
tree | 7f6da94a8d2cacb405c58a651e425a1da6c04c99 /test/exdatatest.c | |
parent | Fix a few internals tests (diff) | |
download | openssl-b3c31a6572bd7b89f469deb3c78f85f6e303df47.tar.xz openssl-b3c31a6572bd7b89f469deb3c78f85f6e303df47.zip |
Fix the error handling in CRYPTO_dup_ex_data.
Fix a strict aliasing issue in ui_dup_method_data.
Add test coverage for CRYPTO_dup_ex_data, use OPENSSL_assert.
Reviewed-by: Rich Salz <rsalz@openssl.org>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2988)
Diffstat (limited to 'test/exdatatest.c')
-rw-r--r-- | test/exdatatest.c | 50 |
1 files changed, 34 insertions, 16 deletions
diff --git a/test/exdatatest.c b/test/exdatatest.c index e82fdbfaea..e0eadd32dd 100644 --- a/test/exdatatest.c +++ b/test/exdatatest.c @@ -10,7 +10,6 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#include <assert.h> #include <openssl/crypto.h> static long saved_argl; @@ -20,26 +19,28 @@ static int saved_idx; static void exnew(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, long argl, void *argp) { - assert(idx == saved_idx); - assert(argl == saved_argl); - assert(argp == saved_argp); + OPENSSL_assert(idx == saved_idx); + OPENSSL_assert(argl == saved_argl); + OPENSSL_assert(argp == saved_argp); + OPENSSL_assert(ptr == NULL); } static int exdup(CRYPTO_EX_DATA *to, const CRYPTO_EX_DATA *from, void *from_d, int idx, long argl, void *argp) { - assert(idx == saved_idx); - assert(argl == saved_argl); - assert(argp == saved_argp); - return 0; + OPENSSL_assert(idx == saved_idx); + OPENSSL_assert(argl == saved_argl); + OPENSSL_assert(argp == saved_argp); + OPENSSL_assert(from_d != NULL); + return 1; } static void exfree(void *parent, void *ptr, CRYPTO_EX_DATA *ad, int idx, long argl, void *argp) { - assert(idx == saved_idx); - assert(argl == saved_argl); - assert(argp == saved_argp); + OPENSSL_assert(idx == saved_idx); + OPENSSL_assert(argl == saved_argl); + OPENSSL_assert(argp == saved_argp); } typedef struct myobj_st { @@ -55,14 +56,14 @@ static MYOBJ *MYOBJ_new() obj->id = ++count; obj->st = CRYPTO_new_ex_data(CRYPTO_EX_INDEX_APP, obj, &obj->ex_data); - assert(obj->st != 0); + OPENSSL_assert(obj->st != 0); return obj; } static void MYOBJ_sethello(MYOBJ *obj, char *cp) { obj->st = CRYPTO_set_ex_data(&obj->ex_data, saved_idx, cp); - assert(obj->st != 0); + OPENSSL_assert(obj->st != 0); } static char *MYOBJ_gethello(MYOBJ *obj) @@ -76,9 +77,19 @@ static void MYOBJ_free(MYOBJ *obj) OPENSSL_free(obj); } +static MYOBJ *MYOBJ_dup(MYOBJ *in) +{ + MYOBJ *obj = MYOBJ_new(); + + obj->st = CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_APP, &obj->ex_data, + &in->ex_data); + OPENSSL_assert(obj->st != 0); + return obj; +} + int main() { - MYOBJ *t1, *t2; + MYOBJ *t1, *t2, *t3; const char *cp; char *p; @@ -92,15 +103,22 @@ int main() t2 = MYOBJ_new(); MYOBJ_sethello(t1, p); cp = MYOBJ_gethello(t1); - assert(cp == p); + OPENSSL_assert(cp == p); if (cp != p) return 1; cp = MYOBJ_gethello(t2); - assert(cp == NULL); + OPENSSL_assert(cp == NULL); if (cp != NULL) return 1; + t3 = MYOBJ_dup(t1); + cp = MYOBJ_gethello(t3); + OPENSSL_assert(cp == p); + if (cp != p) + return 1; + cp = MYOBJ_gethello(t2); MYOBJ_free(t1); MYOBJ_free(t2); + MYOBJ_free(t3); free(saved_argp); free(p); return 0; |