On 4 January 2011 16:54, Dr. Stephen Henson <[email protected]> wrote:

>
> I can't see how that would happen:
>
>
I find a way to reproduce it: just call ENGINE_load_builtin_engines() twice.
Or call ENGINE_load_builtin_engines() after OPENSSL_config() which calls it
too.

It happens because internal ccgost AMETH structures are static (which,
obviously, does matter).
First call of ENGINE_load_builtin_engines() creates new ENGINE structure and
store it in some list, etc.

Second call to ENGINE_load_builtin_engines() creates new engine structure
AGAIN, but AMETH part of it reffers to the same static variable
(ameth_GostR3410_2001).
But ENGINE_add() in second call fails, because engine with the same ID
already in the list.
So, reference count not increased, and just created engine released in the
very next line.
AMETH structures being destoryed, and it makes them invalid for originally
created engine too (because there is only one such structure).


Ways to avoid it:
1. Make ccgost engine allocates AMETH structures dynamically.
As there is no other engines, used this functionality (calls to
ENGINE_set_pkey_asn1_meths() ), I can't compare.
But from my point of view this is a bad idea, because it introduces
unnecessary complexity.
And, there is no clear reason to create them more that once.
Of cource we can imagine some engine which provides different NID_id's
depend on configuration. But ccgost is not the one.

2. Make ENGINE_load_builtin_engines() single-callable.
Just like OPENSSL_config().
I can't see any reason why it have to be called more that once.


Would be really appreciated if guru comment on that.

Andrey.

Reply via email to