Skip to content

Commit cc6e0fc

Browse files
tniessenruyadorno
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 b7aaf3d commit cc6e0fc

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

src/crypto/crypto_spkac.cc

+3-6
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,9 @@ ByteSource ExportChallenge(const ArrayBufferOrViewContents<char>& input) {
100100
if (!sp)
101101
return ByteSource();
102102

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

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

0 commit comments

Comments
 (0)