From 11960235ed80e3ff02a9d7ad63fb95a4800bf108 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 29 Jul 2022 00:00:40 +0200 Subject: [PATCH] src: improve SPKAC::ExportChallenge() Declare buf as an unsigned char to get rid of the reinterpret_cast and do not ignore the return value of ASN1_STRING_TO_UTF8. This also removes the need to call strlen() on the result. PR-URL: https://github.com/nodejs/node/pull/44002 Reviewed-By: Darshan Sen Reviewed-By: Luigi Pinca Reviewed-By: Anna Henningsen --- src/crypto/crypto_spkac.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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) {