Skip to content

Commit 4aec536

Browse files
committed
bson_to_zval() should always initialize state->zchild
This avoids a possible segfault in calling code, were it to zval_ptr_dtor() state->zchild before initialization (i.e. bson_to_zval() returns early on error).
1 parent 6173e60 commit 4aec536

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/bson.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,9 @@ int bson_to_zval(const unsigned char *data, int data_len, php_phongo_bson_state
893893
bool eof = false;
894894
TSRMLS_FETCH();
895895

896+
/* Ensure that state->zchild has a type, since the calling code may want to
897+
* zval_ptr_dtor() it if we throw an exception. */
898+
ZVAL_NULL(state->zchild);
896899

897900
reader = bson_reader_new_from_data(data, data_len);
898901

0 commit comments

Comments
 (0)