Skip to content

Commit 6b39e99

Browse files
committed
Fix parameters double free problem.
1 parent a5876e4 commit 6b39e99

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

phper/src/functions.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ use crate::{
1414
utils::ensure_end_with_zero,
1515
values::{ExecuteData, SetVal, Val},
1616
};
17-
use std::{marker::PhantomData, mem::size_of, ptr::null_mut};
17+
use std::{
18+
marker::PhantomData,
19+
mem::{forget, size_of},
20+
ptr::null_mut,
21+
};
1822

1923
pub(crate) trait Callable {
2024
fn call(&self, execute_data: &mut ExecuteData, arguments: &mut [Val], return_value: &mut Val);
@@ -341,6 +345,12 @@ unsafe extern "C" fn invoke(execute_data: *mut zend_execute_data, return_value:
341345

342346
// TODO catch_unwind for call, translate some panic to throwing Error.
343347
handler.call(execute_data, &mut arguments, return_value);
348+
349+
// Do not call the drop method, because there is the `zend_vm_stack_free_args` call after
350+
// executing function.
351+
for argument in arguments {
352+
forget(argument);
353+
}
344354
}
345355

346356
pub(crate) const fn create_zend_arg_info(

phper/src/values.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,13 @@ impl ExecuteData {
6767
ptr.as_ref().map(|val| val.as_mut_object_unchecked())
6868
}
6969

70+
/// TODO Do not return owned object, because usually Val should not be drop.
7071
pub(crate) unsafe fn get_parameters_array(&mut self) -> Vec<Val> {
7172
let num_args = self.num_args();
7273
let mut arguments = vec![zeroed::<zval>(); num_args as usize];
73-
_zend_get_parameters_array_ex(num_args.into(), arguments.as_mut_ptr());
74+
if num_args > 0 {
75+
_zend_get_parameters_array_ex(num_args.into(), arguments.as_mut_ptr());
76+
}
7477
transmute(arguments)
7578
}
7679
}

0 commit comments

Comments
 (0)