Skip to content

Commit

Permalink
src: improve SPKAC::ExportChallenge()
Browse files Browse the repository at this point in the history
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: #44002
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
tniessen authored and danielleadams committed Aug 11, 2022
1 parent 6bf688d commit 1196023
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/crypto/crypto_spkac.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1196023

Please sign in to comment.