Skip to content

Commit afa22d1

Browse files
committed
Fix crash when in openssl_x509_parse() when i2s_ASN1_INTEGER() fails
The X509_NAME_oneline() function can return NULL, which will cause a crash when the string length is computed via add_assoc_string().
1 parent d9cbc31 commit afa22d1

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ext/openssl/openssl.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2166,6 +2166,12 @@ PHP_FUNCTION(openssl_x509_parse)
21662166
}
21672167

21682168
str_serial = i2s_ASN1_INTEGER(NULL, asn1_serial);
2169+
/* Can return NULL on error or memory allocation failure */
2170+
if (!str_serial) {
2171+
php_openssl_store_errors();
2172+
goto err;
2173+
}
2174+
21692175
add_assoc_string(return_value, "serialNumber", str_serial);
21702176
OPENSSL_free(str_serial);
21712177

0 commit comments

Comments
 (0)