Skip to content

Commit fc4ef43

Browse files
committed
fix leak on failed conversion. new test case
1 parent d572b1b commit fc4ef43

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

ext/snmp/snmp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,8 @@ static bool php_snmp_parse_oid(
678678
ZEND_HASH_FOREACH_VAL(oid_ht, tmp_oid) {
679679
zend_string *tmp = zval_try_get_string(tmp_oid);
680680
if (!tmp) {
681-
continue;
681+
efree(objid_query->vars);
682+
return false;
682683
}
683684
objid_query->vars[objid_query->count].oid = ZSTR_VAL(tmp);
684685
zend_string_release(tmp);

ext/snmp/tests/gh16959.phpt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ var_dump($bad_object_ids);
1717
var_dump(snmpget($hostname, "", $bad_object_ids) === false);
1818
// The array should remain unmodified
1919
var_dump($bad_object_ids);
20+
try {
21+
snmpget($hostname, "", [0 => new stdClass()]);
22+
} catch (Throwable $e) {
23+
echo $e->getMessage();
24+
}
2025
?>
2126
--EXPECTF--
2227
array(4) {
@@ -42,3 +47,4 @@ array(4) {
4247
[0]=>
4348
int(0)
4449
}
50+
Object of class stdClass could not be converted to string

0 commit comments

Comments
 (0)