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 <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
tniessen authored and ruyadorno committed Aug 22, 2022
1 parent b7aaf3d commit cc6e0fc
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 @@ -100,12 +100,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 cc6e0fc

Please sign in to comment.