Skip to content

Commit eb9724f

Browse files
committed
Merge pull request #1036
2 parents 4d58b2c + 02c4820 commit eb9724f

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

scripts/convert-bson-corpus-tests.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
'Int64 type: -1' => 'PHP encodes integers as 32-bit if range allows',
99
'Int64 type: 0' => 'PHP encodes integers as 32-bit if range allows',
1010
'Int64 type: 1' => 'PHP encodes integers as 32-bit if range allows',
11-
'Javascript Code with Scope: bad scope doc (field has bad string length)' => 'Depends on PHPC-889',
1211
'Javascript Code with Scope: Unicode and embedded null in code string, empty scope' => 'Embedded null in code string is not supported in libbson (CDRIVER-1879)',
1312
'Multiple types within the same document: All BSON types' => 'PHP encodes integers as 32-bit if range allows',
1413
'Top-level document validity: Bad $date (number, not string or hash)' => 'Legacy extended JSON $date syntax uses numbers (CDRIVER-2223)',

src/bson.c

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -605,21 +605,37 @@ static bool php_phongo_bson_visit_symbol(const bson_iter_t* iter, const char* ke
605605
return false;
606606
} /* }}} */
607607

608-
static void php_phongo_bson_new_javascript_from_javascript_and_scope(zval* object, const char* code, size_t code_len, const bson_t* scope TSRMLS_DC) /* {{{ */
608+
static bool php_phongo_bson_new_javascript_from_javascript_and_scope(zval* object, const char* code, size_t code_len, const bson_t* scope TSRMLS_DC) /* {{{ */
609609
{
610610
php_phongo_javascript_t* intern;
611611

612+
if (scope) {
613+
php_phongo_bson_state state;
614+
bool valid_scope;
615+
616+
PHONGO_BSON_INIT_STATE(state);
617+
618+
valid_scope = php_phongo_bson_to_zval_ex(bson_get_data(scope), scope->len, &state);
619+
zval_ptr_dtor(&state.zchild);
620+
621+
if (!valid_scope) {
622+
return false;
623+
}
624+
}
625+
612626
object_init_ex(object, php_phongo_javascript_ce);
613627

614628
intern = Z_JAVASCRIPT_OBJ_P(object);
615629
intern->code = estrndup(code, code_len);
616630
intern->code_len = code_len;
617631
intern->scope = scope ? bson_copy(scope) : NULL;
632+
633+
return true;
618634
} /* }}} */
619635

620-
static void php_phongo_bson_new_javascript_from_javascript(zval* object, const char* code, size_t code_len TSRMLS_DC) /* {{{ */
636+
static bool php_phongo_bson_new_javascript_from_javascript(zval* object, const char* code, size_t code_len TSRMLS_DC) /* {{{ */
621637
{
622-
php_phongo_bson_new_javascript_from_javascript_and_scope(object, code, code_len, NULL TSRMLS_CC);
638+
return php_phongo_bson_new_javascript_from_javascript_and_scope(object, code, code_len, NULL TSRMLS_CC);
623639
} /* }}} */
624640

625641
static bool php_phongo_bson_visit_code(const bson_iter_t* iter ARG_UNUSED, const char* key, size_t v_code_len, const char* v_code, void* data) /* {{{ */
@@ -629,7 +645,9 @@ static bool php_phongo_bson_visit_code(const bson_iter_t* iter ARG_UNUSED, const
629645
#if PHP_VERSION_ID >= 70000
630646
zval zchild;
631647

632-
php_phongo_bson_new_javascript_from_javascript(&zchild, v_code, v_code_len TSRMLS_CC);
648+
if (!php_phongo_bson_new_javascript_from_javascript(&zchild, v_code, v_code_len TSRMLS_CC)) {
649+
return true;
650+
}
633651

634652
if (state->is_visiting_array) {
635653
add_next_index_zval(retval, &zchild);
@@ -641,7 +659,10 @@ static bool php_phongo_bson_visit_code(const bson_iter_t* iter ARG_UNUSED, const
641659
TSRMLS_FETCH();
642660

643661
MAKE_STD_ZVAL(zchild);
644-
php_phongo_bson_new_javascript_from_javascript(zchild, v_code, v_code_len TSRMLS_CC);
662+
if (!php_phongo_bson_new_javascript_from_javascript(zchild, v_code, v_code_len TSRMLS_CC)) {
663+
zval_ptr_dtor(&zchild);
664+
return true;
665+
}
645666

646667
if (state->is_visiting_array) {
647668
add_next_index_zval(retval, zchild);
@@ -707,7 +728,9 @@ static bool php_phongo_bson_visit_codewscope(const bson_iter_t* iter ARG_UNUSED,
707728
#if PHP_VERSION_ID >= 70000
708729
zval zchild;
709730

710-
php_phongo_bson_new_javascript_from_javascript_and_scope(&zchild, v_code, v_code_len, v_scope TSRMLS_CC);
731+
if (!php_phongo_bson_new_javascript_from_javascript_and_scope(&zchild, v_code, v_code_len, v_scope TSRMLS_CC)) {
732+
return true;
733+
}
711734

712735
if (state->is_visiting_array) {
713736
add_next_index_zval(retval, &zchild);
@@ -719,7 +742,10 @@ static bool php_phongo_bson_visit_codewscope(const bson_iter_t* iter ARG_UNUSED,
719742
TSRMLS_FETCH();
720743

721744
MAKE_STD_ZVAL(zchild);
722-
php_phongo_bson_new_javascript_from_javascript_and_scope(zchild, v_code, v_code_len, v_scope TSRMLS_CC);
745+
if (!php_phongo_bson_new_javascript_from_javascript_and_scope(zchild, v_code, v_code_len, v_scope TSRMLS_CC)) {
746+
zval_ptr_dtor(&zchild);
747+
return true;
748+
}
723749

724750
if (state->is_visiting_array) {
725751
add_next_index_zval(retval, zchild);

tests/bson-corpus/code_w_scope-decodeError-011.phpt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
--TEST--
22
Javascript Code with Scope: bad scope doc (field has bad string length)
3-
--XFAIL--
4-
Depends on PHPC-889
53
--DESCRIPTION--
64
Generated by scripts/convert-bson-corpus-tests.php
75

0 commit comments

Comments
 (0)