sergot / openssl

OpenSSL bindings for Perl 6
MIT License
14 stars 31 forks source link

Fix OpenSSL::RSAKey sometimes failing to create a key #95

Closed patrickbkr closed 2 years ago

patrickbkr commented 2 years ago

OpenSSL::Bio::BIO_new_mem_buf does not copy its first argument, the buffer to read the key from. Instead it keeps a pointer to that buffer. The returned BIO struct contains said pointer. It is thus important to make sure that that first argument is not GCed until that BIO struct is also out of use. Other wise it can happen, that the buffer is freed by the Raku GC and SSL functions that try to read that BIO receive garbage and thus fail to successfully create a key.

Thanks to @niner for guiding me through debugging at the MoarVM level.