From 30901dc4cd6fdf881e82878387684991a59ad75d Mon Sep 17 00:00:00 2001 From: Pierre Joye Date: Sun, 30 Jul 2006 16:27:03 +0000 Subject: [PATCH] - MFB: #38261, openssl_x509_parse leaks with invalid certs --- ext/openssl/openssl.c | 5 +++++ ext/openssl/tests/bug38261.phpt | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 ext/openssl/tests/bug38261.phpt diff --git a/ext/openssl/openssl.c b/ext/openssl/openssl.c index 656d7e330b..993023ba9b 100644 --- a/ext/openssl/openssl.c +++ b/ext/openssl/openssl.c @@ -770,6 +770,11 @@ static X509 * php_openssl_x509_from_zval(zval ** val, int makeresource, long * r return NULL; } + + if (!(Z_TYPE_PP(val) == IS_STRING || Z_TYPE_PP(val) == IS_OBJECT)) { + return NULL; + } + /* force it to be a string and check if it refers to a file */ convert_to_string_ex(val); diff --git a/ext/openssl/tests/bug38261.phpt b/ext/openssl/tests/bug38261.phpt new file mode 100644 index 0000000000..e7d806083e --- /dev/null +++ b/ext/openssl/tests/bug38261.phpt @@ -0,0 +1,34 @@ +--TEST-- +openssl key from zval leaks +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +bool(false) +bool(false) +bool(false) + +Warning: openssl_x509_parse() expects at least 1 parameter, 0 given in %s/bug38261.php on line %d +NULL +bool(false) + +Catchable fatal error: Object of class stdClass could not be converted to string in %s/bug38261.php on line %d -- 2.50.1