Skip to content

Commit f5ab18c

Browse files
committed
fix: check ASN1_STRING_to_UTF8() failure
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.
1 parent 88555cc commit f5ab18c

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

src/ncrypto.cpp

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

48484848
unsigned char* value_str;
48494849
int value_str_size = ASN1_STRING_to_UTF8(&value_str, value);
4850+
if (value_str_size < 0) [[unlikely]] {
4851+
return {{}, {}};
4852+
}
48504853

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

0 commit comments

Comments
 (0)