Commit dd1abd44 authored by Richard Levitte's avatar Richard Levitte
Browse files

If an engine comes up explicitely, it must also come down explicitely



In apps/apps.c, one can set up an engine with setup_engine().
However, we freed the structural reference immediately, which means
that for engines that don't already have a structural reference
somewhere else (because it's a built in engine), we end up returning
an invalid reference.

Instead, the function release_engine() is added, and called at the end
of the routines that call setup_engine().

Reviewed-by: default avatarRich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/1643)
parent e9722731
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -1280,14 +1280,20 @@ ENGINE *setup_engine(const char *engine, int debug)
        }

        BIO_printf(bio_err, "engine \"%s\" set.\n", ENGINE_get_id(e));

        /* Free our "structural" reference. */
        ENGINE_free(e);
    }
    return e;
}
#endif

void release_engine(ENGINE *e)
{
#ifndef OPENSSL_NO_ENGINE
    if (e != NULL)
        /* Free our "structural" reference. */
        ENGINE_free(e);
#endif
}

static unsigned long index_serial_hash(const OPENSSL_CSTRING *a)
{
    const char *n;
+1 −0
Original line number Diff line number Diff line
@@ -435,6 +435,7 @@ __owur int ctx_set_ctlog_list_file(SSL_CTX *ctx, const char *path);
# else
ENGINE *setup_engine(const char *engine, int debug);
# endif
void release_engine(ENGINE *e);
# ifndef OPENSSL_NO_OCSP
OCSP_RESPONSE *process_responder(OCSP_REQUEST *req,
                                 const char *host, const char *path,
+1 −0
Original line number Diff line number Diff line
@@ -1231,6 +1231,7 @@ end_of_options:
    X509_CRL_free(crl);
    NCONF_free(conf);
    NCONF_free(extconf);
    release_engine(e);
    return (ret);
}

+1 −0
Original line number Diff line number Diff line
@@ -1109,6 +1109,7 @@ int cms_main(int argc, char **argv)
    EVP_PKEY_free(key);
    CMS_ContentInfo_free(cms);
    CMS_ContentInfo_free(rcms);
    release_engine(e);
    BIO_free(rctin);
    BIO_free(in);
    BIO_free(indata);
+1 −0
Original line number Diff line number Diff line
@@ -398,6 +398,7 @@ int dgst_main(int argc, char **argv)
    sk_OPENSSL_STRING_free(macopts);
    OPENSSL_free(sigbuf);
    BIO_free(bmd);
    release_engine(e);
    return (ret);
}

Loading