kaoh / globalplatform

C library + command-line for Open- / GlobalPlatform smart cards
https://kaoh.github.io/globalplatform/
Other
72 stars 30 forks source link

Access violation in crypto.c with OpenSSL 1.1.1g #30

Closed pdnsn closed 4 years ago

pdnsn commented 4 years ago

In calculate_MAC_des_3des function there is a section (0d782e8f65792f2af25c28c7af2ab1cf98bb2b17, crypto.c, line 1167):

EVP_CIPHER_CTX_free(ctx);
//  3DES mode
EVP_CIPHER_CTX_init(ctx);

as directed by this block at the beginning of file:

#if OPENSSL_VERSION_NUMBER < 0x10100000L
#define EVP_CIPHER_CTX_define EVP_CIPHER_CTX *ctx;  EVP_CIPHER_CTX _ctx
#define EVP_CIPHER_CTX_create &_ctx
#define EVP_CIPHER_CTX_free EVP_CIPHER_CTX_cleanup
#else
#define EVP_CIPHER_CTX_define EVP_CIPHER_CTX *ctx
#define EVP_CIPHER_CTX_create EVP_CIPHER_CTX_new()
#endif

For OpenSSL versions 0x10100000L and above EVP_CIPHER_CTX_free is an actual method that frees memory referenced by *ctx pointer, so the following call to EVP_CIPHER_CTX_init throws an access violation exception. I think this shall be resolved by omitting the call to EVP_CIPHER_CTX_free or a call to EVP_CIPHER_CTX_create :

  EVP_CIPHER_CTX_free(ctx);
  //  3DES mode
+ ctx = EVP_CIPHER_CTX_create;
  EVP_CIPHER_CTX_init(ctx);

...at least that is what worked for me

koh-osug commented 4 years ago

Thanks. I will look into this one, this was a change made in the last days, obviously this does not work. I think 2 more locations are affected.

kaoh commented 4 years ago

I have committed a patch, please check. The Homebrew packages are also updated.

pdnsn commented 4 years ago

Now it's ok (at least on Win32). Thank you for quick reaction.