crypto: handle initEDRaw pkey failure
Refs https://github.com/electron/electron/pull/31087.
It's possible that https://github.com/nodejs/node/blob/4441c3e3b5c3b0fdc97e5097db708421d90814a6/src/crypto/crypto_keys.cc#L1106 will fail, and KeyObjectHandle::InitEDRaw
will set the return value to false. This means that the data_
member will never be assigned. However, the return value of this function is never checked by any of its callsites, meaning that a keyObject is returned but that calling any functions on it, e.g. export
or asymmetricKeyType
will cause a nullptr crash when they try to access key->Data()
.
Fix this by checking the return value from handle.initEdRaw()
and throwing an error on false
.
I used the error from above the callsites but please let me know if there's another preferable one!