Hey Marcus,

This is confusing, isn't it? That's understandable... I would recommend reading
the manual for engine, either with 'man engine' if you have it installed, or by
reading doc/crypto/engine.pod, the subsection "Reference counting and handles"
talks quite extensively about structural and functional references. Take note
that when a functional reference is added, so is a structural reference.
ENGINE_free() removes structural references.

So, going to setup_engine, you can first note the call to ENGINE_by_id and
try_load_engine. One of those will add a structural reference. A few lines
further down, you'll notice ENGINE_set_default, which is called to check that
the engine is at all functional; this one adds a functional reference as well
as a structural one, but we don't want to pass that back to the caller.
ENGINE_set_default has a side effect in that it sets up the given engine to
provide OpenSSL with the cipher and digest algorithms it contains.

The ENGINE_free that you spotted will free the structural reference that
ENGINE_set_default added, but the one that ENGINE_by_id created will remain.
Therefore, e is still meaningful when being returned.

I cannot answer for Coverty. If you have personally experienced a problem,
please tell us more in a new ticket with a bit more detail.

On Tue May 24 21:11:12 2011, [email protected] wrote:
> HI,
>
> apps/engine.c, function setup_engine()
>
> It has "return e;" on success,
> but the code has:
>
>
> /* Free our "structural" reference. */
> ENGINE_free(e);
> }
> return e;
>
> ENGINE_free(e) makes e invalid, so returning it is very dangerous.
>
> The return value mostly seems to be unused though, so perhaps
> get fully rid of it.
>
> Spotted also by Coverity.
>
> Ciao, Marcus


--
Richard Levitte
[email protected]

______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [email protected]
Automated List Manager                           [email protected]

Reply via email to