Skip to content

Commit aeec5b4

Browse files
committed
MFH: fix #39125 (Memleak when reflecting non-existing class/method)
1 parent e206506 commit aeec5b4

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ PHP NEWS
44
- Fixed bug #38458, PECL bug #8944, PECL bug #7775 (error retrieving
55
columns after long/text columns with PDO_ODBC). (Wez)
66
- Fixed PECL bug #8816 (issue in php_oci_statement_fetch with more than one
7+
piecewise column) (jeff at badtz-maru dot com, Tony)
78
- Fixed PECL bug #7755 (error selecting DOUBLE fields with PDO_ODBC).
89
("slaws", Wez)
9-
piecewise column) (jeff at badtz-maru dot com, Tony)
10+
- Fixed bug #39125 (Memleak when reflecting non-existing class/method). (Tony)
1011
- Fixed bug #39067 (getDeclaringClass() and private properties). (Tony)
1112
- Fixed bug #39034 (curl_exec() with return transfer returns TRUE on empty
1213
files). (Ilia)

ext/reflection/php_reflection.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,6 +2165,7 @@ ZEND_METHOD(reflection_method, __construct)
21652165
return;
21662166
}
21672167
if ((tmp = strstr(name_str, "::")) == NULL) {
2168+
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC, "Invalid method name %s", name_str);
21682169
return;
21692170
}
21702171
classname = &ztmp;
@@ -2186,6 +2187,9 @@ ZEND_METHOD(reflection_method, __construct)
21862187
if (zend_lookup_class(Z_STRVAL_P(classname), Z_STRLEN_P(classname), &pce TSRMLS_CC) == FAILURE) {
21872188
zend_throw_exception_ex(reflection_exception_ptr, 0 TSRMLS_CC,
21882189
"Class %s does not exist", Z_STRVAL_P(classname));
2190+
if (classname == &ztmp) {
2191+
zval_dtor(&ztmp);
2192+
}
21892193
return;
21902194
}
21912195
ce = *pce;
@@ -2196,6 +2200,9 @@ ZEND_METHOD(reflection_method, __construct)
21962200
break;
21972201

21982202
default:
2203+
if (classname == &ztmp) {
2204+
zval_dtor(&ztmp);
2205+
}
21992206
_DO_THROW("The parameter class is expected to be either a string or an object");
22002207
/* returns out of this function */
22012208
}

ext/reflection/tests/008.phpt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
ReflectionMethod::__construct() tests
3+
--FILE--
4+
<?php
5+
6+
$a = array("", 1, "::", "a::", "::b", "a::b");
7+
8+
foreach ($a as $val) {
9+
try {
10+
new ReflectionMethod($val);
11+
} catch (Exception $e) {
12+
var_dump($e->getMessage());
13+
}
14+
}
15+
16+
$a = array("", 1, "");
17+
$b = array("", "", 1);
18+
19+
foreach ($a as $key=>$val) {
20+
try {
21+
new ReflectionMethod($val, $b[$key]);
22+
} catch (Exception $e) {
23+
var_dump($e->getMessage());
24+
}
25+
}
26+
27+
echo "Done\n";
28+
?>
29+
--EXPECTF--
30+
string(20) "Invalid method name "
31+
string(21) "Invalid method name 1"
32+
string(21) "Class does not exist"
33+
string(22) "Class a does not exist"
34+
string(21) "Class does not exist"
35+
string(22) "Class a does not exist"
36+
string(21) "Class does not exist"
37+
string(66) "The parameter class is expected to be either a string or an object"
38+
string(21) "Class does not exist"
39+
Done

0 commit comments

Comments
 (0)