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 <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
Tobias Nießen 2022-07-29 00:00:40 +02:00 committed by GitHub
parent 0616eafbc8
commit 28a9042ee6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,12 +99,9 @@ ByteSource ExportChallenge(const ArrayBufferOrViewContents<char>& input) {
if (!sp)
return ByteSource();
char* buf = nullptr;
ASN1_STRING_to_UTF8(
reinterpret_cast<unsigned char**>(&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<Value>& args) {