Skip to content

Commit a42aafb

Browse files
ndosscheaduh95
authored andcommitted
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 ba80f7b commit a42aafb

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
@@ -6904,6 +6904,9 @@ std::pair<std::string, std::string> X509Name::Iterator::operator*() const {
69046904

69056905
unsigned char* value_str;
69066906
int value_str_size = ASN1_STRING_to_UTF8(&value_str, value);
6907+
if (value_str_size < 0) [[unlikely]] {
6908+
return {{}, {}};
6909+
}
69076910

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

0 commit comments

Comments
 (0)