Skip to content

Commit 9547daf

Browse files
committed
Fix use after free
1 parent af8e7d0 commit 9547daf

File tree

5 files changed

+14
-15
lines changed

5 files changed

+14
-15
lines changed

src/args.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ impl<'a> Arg<'a> {
9898
where
9999
T: FromZvalMut<'a>,
100100
{
101-
self.zval.as_mut().and_then(|zv| T::from_zval_mut(zv.dereference_mut()))
101+
self.zval
102+
.as_mut()
103+
.and_then(|zv| T::from_zval_mut(zv.dereference_mut()))
102104
}
103105

104106
/// Attempts to return a reference to the arguments internal Zval.

src/types/zval.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@ impl Zval {
5353

5454
/// Dereference the zval, if it is a reference.
5555
pub fn dereference(&self) -> &Self {
56-
return self
57-
.reference()
58-
.or_else(|| self.indirect())
59-
.unwrap_or(self)
56+
return self.reference().or_else(|| self.indirect()).unwrap_or(self);
6057
}
6158

6259
/// Dereference the zval mutable, if it is a reference.
6360
pub fn dereference_mut(&mut self) -> &mut Self {
61+
// TODO: probably more ZTS work is needed here
6462
if self.is_reference() {
6563
#[allow(clippy::unwrap_used)]
6664
return self.reference_mut().unwrap();

src/zend/_type.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
use std::{
2-
ffi::c_void,
3-
ptr,
4-
};
1+
use std::{ffi::c_void, ptr};
52

63
use crate::{
74
ffi::{
85
zend_type, IS_MIXED, MAY_BE_ANY, MAY_BE_BOOL, _IS_BOOL, _ZEND_IS_VARIADIC_BIT,
96
_ZEND_SEND_MODE_SHIFT, _ZEND_TYPE_NAME_BIT, _ZEND_TYPE_NULLABLE_BIT,
107
},
11-
flags::DataType, types::ZendStr,
8+
flags::DataType,
9+
types::ZendStr,
1210
};
1311

1412
/// Internal Zend type.
@@ -82,7 +80,7 @@ impl ZendType {
8280
allow_null: bool,
8381
) -> Option<Self> {
8482
Some(Self {
85-
ptr: ZendStr::new(class_name, true).as_ptr() as *mut c_void,
83+
ptr: ZendStr::new(class_name, true).into_raw().as_ptr() as *mut c_void,
8684
type_mask: _ZEND_TYPE_NAME_BIT
8785
| (if allow_null {
8886
_ZEND_TYPE_NULLABLE_BIT

src/zend/try_catch.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ pub fn try_catch<R, F: FnMut() -> R + RefUnwindSafe>(func: F) -> Result<R, Catch
3535

3636
/// PHP propose a try catch mechanism in C using setjmp and longjmp (bailout)
3737
/// It store the arg of setjmp into the bailout field of the global executor
38-
/// If a bailout is triggered, the executor will jump to the setjmp and restore the previous setjmp
38+
/// If a bailout is triggered, the executor will jump to the setjmp and restore
39+
/// the previous setjmp
3940
///
4041
/// try_catch_first allow to use this mechanism
4142
///
42-
/// This functions differs from ['try_catch'] as it also initialize the bailout mechanism
43-
/// for the first time
43+
/// This functions differs from ['try_catch'] as it also initialize the bailout
44+
/// mechanism for the first time
4445
///
4546
/// # Returns
4647
///

tests/src/integration/closure.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
$v = test_closure();
66

77
// Closure
8-
assert($closure('works') === 'works');
8+
assert($v('works') === 'works');
99

1010
// Closure once
1111
$closure = test_closure_once('test');

0 commit comments

Comments
 (0)