diff --git a/src/crypto/crypto_spkac.cc b/src/crypto/crypto_spkac.cc index 7cda346907e421..3489dee33784cc 100644 --- a/src/crypto/crypto_spkac.cc +++ b/src/crypto/crypto_spkac.cc @@ -99,12 +99,9 @@ ByteSource ExportChallenge(const ArrayBufferOrViewContents& input) { if (!sp) return ByteSource(); - char* buf = nullptr; - ASN1_STRING_to_UTF8( - reinterpret_cast(&buf), - sp->spkac->challenge); - - return ByteSource::Allocated(buf, strlen(buf)); + unsigned char* buf = nullptr; + int buf_size = ASN1_STRING_to_UTF8(&buf, sp->spkac->challenge); + return (buf_size >= 0) ? ByteSource::Allocated(buf, buf_size) : ByteSource(); } void ExportChallenge(const FunctionCallbackInfo& args) {