Skip to content

Commit 575abdf

Browse files
authored
crypto: fix missing error checks on ASN1_STRING_to_UTF8()
This function returns a negative error code on error. When it does so, the `value_str` pointer will remain uninitialized and cause a crash later on when it is freed by OPENSSL_free(). Even if it wouldn't crash there, it still fails to signal the error and an empty string may be propagated to the callers. The check also mirrors the other one in the same file. Signed-off-by: ndossche <nora.dossche@ugent.be> PR-URL: #65200 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
1 parent c4cfa63 commit 575abdf

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

‎deps/ncrypto/ncrypto.cc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6983,6 +6983,9 @@ std::pair<std::string, std::string> X509Name::Iterator::operator*() const {
69836983

69846984
unsigned char* value_str;
69856985
int value_str_size = ASN1_STRING_to_UTF8(&value_str, value);
6986+
if (value_str_size < 0) [[unlikely]] {
6987+
return {{}, {}};
6988+
}
69866989

69876990
std::string out(reinterpret_cast<const char*>(value_str), value_str_size);
69886991
OPENSSL_free(value_str); // free after copy

0 commit comments

Comments
 (0)