Skip to content

Commit 1196023

Browse files
tniessendanielleadams
authored andcommitted
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: #44002 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 6bf688d commit 1196023

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/crypto/crypto_spkac.cc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,9 @@ ByteSource ExportChallenge(const ArrayBufferOrViewContents<char>& input) {
9999
if (!sp)
100100
return ByteSource();
101101

102-
char* buf = nullptr;
103-
ASN1_STRING_to_UTF8(
104-
reinterpret_cast<unsigned char**>(&buf),
105-
sp->spkac->challenge);
106-
107-
return ByteSource::Allocated(buf, strlen(buf));
102+
unsigned char* buf = nullptr;
103+
int buf_size = ASN1_STRING_to_UTF8(&buf, sp->spkac->challenge);
104+
return (buf_size >= 0) ? ByteSource::Allocated(buf, buf_size) : ByteSource();
108105
}
109106

110107
void ExportChallenge(const FunctionCallbackInfo<Value>& args) {

0 commit comments

Comments
 (0)