Skip to content

Commit ef4241c

Browse files
committed
PHPC-988: Check for TypeWrapper::createFromBSONType() exception
If the userland function throws, we should return early and avoid assigning the uninitialized return value (zwrapper) to zchild. On PHP 5.x, such an assignment could cause a segfault.
1 parent 36487bc commit ef4241c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/bson.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@
4747
zval zwrapper; \
4848
zend_call_method_with_1_params(NULL, wrapper_ce, NULL, "createfrombsontype", &zwrapper, &(zchild)); \
4949
zval_ptr_dtor(&(zchild)); \
50+
if (EG(exception)) { \
51+
return false; \
52+
} \
5053
ZVAL_COPY_VALUE(&(zchild), &zwrapper); \
5154
}
5255
#else
@@ -55,6 +58,9 @@
5558
zval *zwrapper; \
5659
zend_call_method_with_1_params(NULL, wrapper_ce, NULL, "createfrombsontype", &zwrapper, (zchild)); \
5760
zval_ptr_dtor(&(zchild)); \
61+
if (EG(exception)) { \
62+
return false; \
63+
} \
5864
zchild = zwrapper; \
5965
}
6066
#endif

0 commit comments

Comments
 (0)