ASYNC_start_job: Reset libctx when async_fibre_swapcontext fails
authorTomas Mraz <tomas@openssl.org>
Thu, 18 Mar 2021 12:04:30 +0000 (13:04 +0100)
committerTomas Mraz <tomas@openssl.org>
Fri, 19 Mar 2021 13:25:00 +0000 (14:25 +0100)
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14605)

crypto/async/async.c

index 963d969d982109fcbe6344f6c1f1ee049d07bb96..2a51ee7bc2b26805a5fcc540b6a4081214673f9f 100644 (file)
@@ -209,9 +209,15 @@ int ASYNC_start_job(ASYNC_JOB **job, ASYNC_WAIT_CTX *wctx, int *ret,
                  * fibre ran
                  */
                 libctx = OSSL_LIB_CTX_set0_default(ctx->currjob->libctx);
+                if (libctx == NULL) {
+                    /* Failed to set the default context */
+                    ERR_raise(ERR_LIB_ASYNC, ERR_R_INTERNAL_ERROR);
+                    goto err;
+                }
                 /* Resume previous job */
                 if (!async_fibre_swapcontext(&ctx->dispatcher,
                         &ctx->currjob->fibrectx, 1)) {
+                    ctx->currjob->libctx = OSSL_LIB_CTX_set0_default(libctx);
                     ERR_raise(ERR_LIB_ASYNC, ASYNC_R_FAILED_TO_SWAP_CONTEXT);
                     goto err;
                 }