X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=crypto%2Fex_data.c;h=22c4d3d9b904d73c5db4117faf59467e272de597;hb=43a0449fe6ce18b750803be8a115a412a7235496;hp=4a3201a9535591f062bbd752698782673eb542ec;hpb=b3c31a6572bd7b89f469deb3c78f85f6e303df47;p=openssl.git diff --git a/crypto/ex_data.c b/crypto/ex_data.c index 4a3201a953..22c4d3d9b9 100644 --- a/crypto/ex_data.c +++ b/crypto/ex_data.c @@ -287,7 +287,14 @@ int CRYPTO_dup_ex_data(int class_index, CRYPTO_EX_DATA *to, CRYPTOerr(CRYPTO_F_CRYPTO_DUP_EX_DATA, ERR_R_MALLOC_FAILURE); return 0; } - if (!CRYPTO_set_ex_data(to, mx - 1, NULL)) + /* + * Make sure the ex_data stack is at least |mx| elements long to avoid + * issues in the for loop that follows; so go get the |mx|'th element + * (if it does not exist CRYPTO_get_ex_data() returns NULL), and assign + * to itself. This is normally a no-op; but ensures the stack is the + * proper size + */ + if (!CRYPTO_set_ex_data(to, mx - 1, CRYPTO_get_ex_data(to, mx - 1))) goto err; for (i = 0; i < mx; i++) {