com php-src: Merge branch 'PHP-5.6' into PHP-7.0: ext/standard/tests/serialize/bug70963.phpt ext/standard/var_u nserializer.c
ext/standard/var_unserializer.re
| From: | Nikita Popov | Date: | Wed, 04 Jan 2017 23:24:25 +0000 |
| Subject: | com php-src: Merge branch 'PHP-5.6' into PHP-7.0: ext/standard/tests/serialize/bug70963.phpt ext/standard/var_u nserializer.c ext/standard/var_unserializer.re |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-96556@lists.php.net to get a copy of this message | ||
Commit: b47c49d7a00bc34d7e0f3d72732f66e904da6fa7
Author: Nikita Popov <nikic@php.net> Thu, 5 Jan 2017 00:22:25 +0100
Parents: 125578c63600796e76e5a7595292150d1b540cf7 f697874e3f294623c1c1ca00fb98edf98cddcc67
Branches: PHP-7.0 PHP-7.1
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=b47c49d7a00bc34d7e0f3d72732f66e904da6fa7
Log:
Merge branch 'PHP-5.6' into PHP-7.0
Changed paths:
MA ext/standard/tests/serialize/bug70963.phpt
MM ext/standard/var_unserializer.c
MM ext/standard/var_unserializer.re
diff --cc ext/standard/tests/serialize/bug70963.phpt index 93843c6,0000000..0bdfb2c mode 100644,000000..100644 --- a/ext/standard/tests/serialize/bug70963.phpt +++ b/ext/standard/tests/serialize/bug70963.phpt @@@ -1,42 -1,0 +1,46 @@@ +--TEST-- +Bug #70963 (Unserialize shows UNKNOW in result) +--FILE-- +<?php +var_dump(unserialize('a:2:{i:0;O:9:"exception":1:{s:16:"'."\0".'Exception'."\0".'trace";s:4:"test";}i:1;R:3;}')); +var_dump(unserialize('a:2:{i:0;O:9:"exception":1:{s:16:"'."\0".'Exception'."\0".'trace";s:4:"test";}i:1;r:3;}')); +?> +--EXPECTF-- - array(1) { ++array(2) { + [0]=> + object(Exception)#%d (6) { + ["message":protected]=> + string(0) "" + ["string":"Exception":private]=> + string(0) "" + ["code":protected]=> + int(0) + ["file":protected]=> + string(%d) "%s" + ["line":protected]=> + int(2) + ["previous":"Exception":private]=> + NULL + } ++ [1]=> ++ string(4) "test" +} - array(1) { ++array(2) { + [0]=> + object(Exception)#%d (6) { + ["message":protected]=> + string(0) "" + ["string":"Exception":private]=> + string(0) "" + ["code":protected]=> + int(0) + ["file":protected]=> + string(%d) "%s" + ["line":protected]=> + int(3) + ["previous":"Exception":private]=> + NULL + } ++ [1]=> ++ string(4) "test" +} diff --cc ext/standard/var_unserializer.c index 0b1de2c,6706866..76688b9 --- a/ext/standard/var_unserializer.c +++ b/ext/standard/var_unserializer.c @@@ -28,9 -28,14 +28,12 @@@ #define VAR_ENTRIES_MAX 1024 #define VAR_ENTRIES_DBG 0 ++/* VAR_FLAG used in var_dtor entries to signify an entry on which __wakeup should be called */ + #define VAR_WAKEUP_FLAG 1 -#define WITH_WAKEUP_FLAG(zv_ptr) ((zval *) ((zend_uintptr_t) zv_ptr | VAR_WAKEUP_FLAG)) -#define WITHOUT_WAKEUP_FLAG(zv_ptr) ((zval *) ((zend_uintptr_t) zv_ptr & ~VAR_WAKEUP_FLAG)) -#define HAS_WAKEUP_FLAG(zv_ptr) ((zend_uintptr_t) zv_ptr & VAR_WAKEUP_FLAG) + typedef struct { zval *data[VAR_ENTRIES_MAX]; - long used_slots; + zend_long used_slots; void *next; } var_entries; @@@ -82,29 -109,33 +85,30 @@@ PHPAPI zval *var_tmp_var(php_unserializ } var_hash = (*var_hashx)->last_dtor; -#if VAR_ENTRIES_DBG - fprintf(stderr, "var_push_dtor_no_addref(%p, %ld): %d (%d)\n", *rval, var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(rval), Z_REFCOUNT_PP(rval)); -#endif - - if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) { - var_hash = emalloc(sizeof(var_entries)); - var_hash->used_slots = 0; - var_hash->next = 0; - - if (!(*var_hashx)->first_dtor) { - (*var_hashx)->first_dtor = var_hash; - } else { - ((var_entries *) (*var_hashx)->last_dtor)->next = var_hash; - } - - (*var_hashx)->last_dtor = var_hash; - } - - var_hash->data[var_hash->used_slots++] = *rval; + if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) { + var_hash = emalloc(sizeof(var_dtor_entries)); + var_hash->used_slots = 0; + var_hash->next = 0; + + if (!(*var_hashx)->first_dtor) { + (*var_hashx)->first_dtor = var_hash; + } else { + ((var_dtor_entries *) (*var_hashx)->last_dtor)->next = var_hash; + } + + (*var_hashx)->last_dtor = var_hash; + } + ZVAL_UNDEF(&var_hash->data[var_hash->used_slots]); ++ Z_VAR_FLAGS(var_hash->data[var_hash->used_slots]) = 0; + return &var_hash->data[var_hash->used_slots++]; } -PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval) +PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval *nzval) { - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; #if VAR_ENTRIES_DBG - fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(nzval)); + fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_P(nzval)); #endif while (var_hash) { @@@ -140,9 -173,11 +144,13 @@@ static zval *var_access(php_unserialize PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) { void *next; - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; + var_dtor_entries *var_dtor_hash = (*var_hashx)->first_dtor; + zend_bool wakeup_failed = 0; - TSRMLS_FETCH(); ++ zval wakeup_name; ++ ZVAL_UNDEF(&wakeup_name); + #if VAR_ENTRIES_DBG fprintf(stderr, "var_destroy(%ld)\n", var_hash?var_hash->used_slots:-1L); #endif @@@ -153,17 -188,44 +161,42 @@@ var_hash = next; } - var_hash = (*var_hashx)->first_dtor; - - while (var_hash) { - for (i = 0; i < var_hash->used_slots; i++) { - zval *zv = var_hash->data[i]; + while (var_dtor_hash) { + for (i = 0; i < var_dtor_hash->used_slots; i++) { ++ zval *zv = &var_dtor_hash->data[i]; #if VAR_ENTRIES_DBG - fprintf(stderr, "var_destroy dtor(%p, %ld)\n", var_hash->data[i], Z_REFCOUNT_P(var_hash->data[i])); + fprintf(stderr, "var_destroy dtor(%p, %ld)\n", var_dtor_hash->data[i], Z_REFCOUNT_P(var_dtor_hash->data[i])); #endif - zval_ptr_dtor(&var_dtor_hash->data[i]); + - if (HAS_WAKEUP_FLAG(zv)) { - zv = WITHOUT_WAKEUP_FLAG(zv); ++ /* Perform delayed __wakeup calls */ ++ if (Z_VAR_FLAGS_P(zv) == VAR_WAKEUP_FLAG) { + if (!wakeup_failed) { - zval *retval_ptr = NULL; - zval wakeup_name; - INIT_PZVAL(&wakeup_name); - ZVAL_STRINGL(&wakeup_name, "__wakeup", sizeof("__wakeup") - 1, 0); ++ zval retval; ++ if (Z_ISUNDEF(wakeup_name)) { ++ ZVAL_STRINGL(&wakeup_name, "__wakeup", sizeof("__wakeup") - 1); ++ } + + BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), &zv, &wakeup_name, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC) == FAILURE || retval_ptr == NULL) { ++ if (call_user_function_ex(CG(function_table), zv, &wakeup_name, &retval, 0, 0, 1, NULL) == FAILURE || Z_ISUNDEF(retval)) { + wakeup_failed = 1; - zend_object_store_ctor_failed(zv TSRMLS_CC); ++ GC_FLAGS(Z_OBJ_P(zv)) |= IS_OBJ_DESTRUCTOR_CALLED; + } + BG(serialize_lock)--; + - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } ++ zval_ptr_dtor(&retval); + } else { - zend_object_store_ctor_failed(zv TSRMLS_CC); ++ GC_FLAGS(Z_OBJ_P(zv)) |= IS_OBJ_DESTRUCTOR_CALLED; + } + } + - zval_ptr_dtor(&zv); ++ zval_ptr_dtor(zv); } - next = var_hash->next; - efree(var_hash); - var_hash = next; + next = var_dtor_hash->next; + efree_size(var_dtor_hash, sizeof(var_dtor_entries)); + var_dtor_hash = next; } ++ ++ zval_ptr_dtor(&wakeup_name); } /* }}} */ @@@ -238,7 -280,7 +271,7 @@@ static inline int unserialize_allowed_c #define YYMARKER marker - #line 246 "ext/standard/var_unserializer.re" -#line 288 "ext/standard/var_unserializer.re" ++#line 279 "ext/standard/var_unserializer.re" @@@ -457,14 -468,9 +490,12 @@@ static inline zend_long object_common1( #ifdef PHP_WIN32 # pragma optimize("", off) #endif -static inline int object_common2(UNSERIALIZE_PARAMETER, long elements) +static inline int object_common2(UNSERIALIZE_PARAMETER, zend_long elements) { - zval retval; - zval fname; - if (Z_TYPE_PP(rval) != IS_OBJECT) { + HashTable *ht; + zend_bool has_wakeup; + + if (Z_TYPE_P(rval) != IS_OBJECT) { return 0; } @@@ -481,20 -483,22 +512,12 @@@ return 0; } - if (Z_TYPE_PP(rval) != IS_OBJECT) { - return 0; - } - - if (Z_OBJCE_PP(rval) != PHP_IC_ENTRY && - zend_hash_exists(&Z_OBJCE_PP(rval)->function_table, "__wakeup", sizeof("__wakeup")) - ) { - /* Store object for delayed __wakeup call. Remove references. */ - zval **slot = get_var_push_dtor_slot(var_hash); - zval *zv = *rval; - Z_ADDREF_P(zv); - if (PZVAL_IS_REF(zv)) { - SEPARATE_ZVAL(&zv); - } - *slot = WITH_WAKEUP_FLAG(zv); + ZVAL_DEREF(rval); + if (has_wakeup) { - ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1); - BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), rval, &fname, &retval, 0, 0, 1, NULL) == FAILURE || Z_ISUNDEF(retval)) { - GC_FLAGS(Z_OBJ_P(rval)) |= IS_OBJ_DESTRUCTOR_CALLED; - } - BG(serialize_lock)--; - zval_dtor(&fname); - zval_dtor(&retval); - } - - if (EG(exception)) { - return 0; ++ /* Delay __wakeup call until end of serialization */ ++ zval *wakeup_var = var_tmp_var(var_hash); ++ ZVAL_COPY(wakeup_var, rval); ++ Z_VAR_FLAGS_P(wakeup_var) = VAR_WAKEUP_FLAG; } return finish_nested_data(UNSERIALIZE_PASSTHRU); @@@ -555,7 -527,9 +578,7 @@@ static int php_var_unserialize_internal start = cursor; - #line 559 "ext/standard/var_unserializer.c" - - -#line 533 "ext/standard/var_unserializer.c" ++#line 582 "ext/standard/var_unserializer.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@@ -597,30 -570,29 +619,29 @@@ yych = *YYCURSOR; switch (yych) { case 'C': - case 'O': goto yy13; + case 'O': goto yy4; case 'N': goto yy5; - case 'R': goto yy2; - case 'S': goto yy10; - case 'a': goto yy11; - case 'b': goto yy6; - case 'd': goto yy8; - case 'i': goto yy7; + case 'R': goto yy6; + case 'S': goto yy7; + case 'a': goto yy8; + case 'b': goto yy9; + case 'd': goto yy10; + case 'i': goto yy11; case 'o': goto yy12; - case 'r': goto yy4; - case 's': goto yy9; - case '}': goto yy14; - default: goto yy16; + case 'r': goto yy13; + case 's': goto yy14; + case '}': goto yy15; + default: goto yy2; } yy2: - yych = *(YYMARKER = ++YYCURSOR); - if (yych == ':') goto yy95; + ++YYCURSOR; yy3: - #line 936 "ext/standard/var_unserializer.re" -#line 909 "ext/standard/var_unserializer.re" ++#line 959 "ext/standard/var_unserializer.re" { return 0; } - #line 621 "ext/standard/var_unserializer.c" -#line 593 "ext/standard/var_unserializer.c" ++#line 642 "ext/standard/var_unserializer.c" yy4: yych = *(YYMARKER = ++YYCURSOR); - if (yych == ':') goto yy89; + if (yych == ':') goto yy17; goto yy3; yy5: yych = *++YYCURSOR; @@@ -656,20 -628,21 +677,21 @@@ yy12 goto yy3; yy13: yych = *(YYMARKER = ++YYCURSOR); - if (yych == ':') goto yy17; + if (yych == ':') goto yy28; goto yy3; yy14: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == ':') goto yy29; + goto yy3; + yy15: ++YYCURSOR; - #line 930 "ext/standard/var_unserializer.re" -#line 903 "ext/standard/var_unserializer.re" ++#line 953 "ext/standard/var_unserializer.re" { /* this is the case where we have less data than planned */ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unexpected end of serialized data"); + php_error_docref(NULL, E_NOTICE, "Unexpected end of serialized data"); return 0; /* not sure if it should be 0 or 1 here? */ } - #line 670 "ext/standard/var_unserializer.c" - yy16: - yych = *++YYCURSOR; - goto yy3; -#line 646 "ext/standard/var_unserializer.c" ++#line 695 "ext/standard/var_unserializer.c" yy17: yych = *++YYCURSOR; if (yybm[0+yych] & 128) { @@@ -680,191 -653,110 +702,109 @@@ yy18 YYCURSOR = YYMARKER; goto yy3; yy19: + ++YYCURSOR; -#line 581 "ext/standard/var_unserializer.re" ++#line 637 "ext/standard/var_unserializer.re" + { + *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_NULL(*rval); ++ ZVAL_NULL(rval); + return 1; + } -#line 665 "ext/standard/var_unserializer.c" ++#line 713 "ext/standard/var_unserializer.c" + yy21: yych = *++YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy20; + if (yych <= ',') { + if (yych == '+') goto yy33; + goto yy18; + } else { + if (yych <= '-') goto yy33; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy34; + goto yy18; } + yy22: + yych = *++YYCURSOR; + if (yych == '+') goto yy36; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy37; goto yy18; - yy20: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy20; - } + yy23: + yych = *++YYCURSOR; + if (yych == '+') goto yy39; if (yych <= '/') goto yy18; - if (yych >= ';') goto yy18; + if (yych <= '9') goto yy40; + goto yy18; + yy24: yych = *++YYCURSOR; - if (yych != '"') goto yy18; - ++YYCURSOR; - #line 778 "ext/standard/var_unserializer.re" - { - size_t len, len2, len3, maxlen; - zend_long elements; - char *str; - zend_string *class_name; - zend_class_entry *ce; - int incomplete_class = 0; - - int custom_object = 0; - - zval user_func; - zval retval; - zval args[1]; - - if (!var_hash) return 0; - if (*start == 'C') { - custom_object = 1; - } - - len2 = len = parse_uiv(start + 2); - maxlen = max - YYCURSOR; - if (maxlen < len || len == 0) { - *p = start + 2; - return 0; - } - - str = (char*)YYCURSOR; - - YYCURSOR += len; - - if (*(YYCURSOR) != '"') { - *p = YYCURSOR; - return 0; - } - if (*(YYCURSOR+1) != ':') { - *p = YYCURSOR+1; - return 0; - } - - len3 = strspn(str, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\"); - if (len3 != len) - { - *p = YYCURSOR + len3 - len; - return 0; - } - - class_name = zend_string_init(str, len, 0); - - do { - if(!unserialize_allowed_class(class_name, classes)) { - incomplete_class = 1; - ce = PHP_IC_ENTRY; - break; - } - - /* Try to find class directly */ - BG(serialize_lock)++; - ce = zend_lookup_class(class_name); - if (ce) { - BG(serialize_lock)--; - if (EG(exception)) { - zend_string_release(class_name); - return 0; - } - break; - } - BG(serialize_lock)--; - - if (EG(exception)) { - zend_string_release(class_name); - return 0; - } - - /* Check for unserialize callback */ - if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) { - incomplete_class = 1; - ce = PHP_IC_ENTRY; - break; - } - - /* Call unserialize callback */ - ZVAL_STRING(&user_func, PG(unserialize_callback_func)); - - ZVAL_STR_COPY(&args[0], class_name); - BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL) != SUCCESS) { - BG(serialize_lock)--; - if (EG(exception)) { - zend_string_release(class_name); - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&args[0]); - return 0; - } - php_error_docref(NULL, E_WARNING, "defined (%s) but not found", Z_STRVAL(user_func)); - incomplete_class = 1; - ce = PHP_IC_ENTRY; - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&args[0]); - break; - } - BG(serialize_lock)--; - zval_ptr_dtor(&retval); - if (EG(exception)) { - zend_string_release(class_name); - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&args[0]); - return 0; - } - - /* The callback function may have defined the class */ - BG(serialize_lock)++; - if ((ce = zend_lookup_class(class_name)) == NULL) { - php_error_docref(NULL, E_WARNING, "Function %s() hasn't defined the class it was called for", Z_STRVAL(user_func)); - incomplete_class = 1; - ce = PHP_IC_ENTRY; + if (yych <= '/') goto yy18; + if (yych <= '1') goto yy42; + goto yy18; + yy25: + yych = *++YYCURSOR; + if (yych <= '/') { + if (yych <= ',') { + if (yych == '+') goto yy43; + goto yy18; + } else { + if (yych <= '-') goto yy44; + if (yych <= '.') goto yy45; + goto yy18; } - BG(serialize_lock)--; - - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&args[0]); - break; - } while (1); - - *p = YYCURSOR; - - if (custom_object) { - int ret; - - ret = object_custom(UNSERIALIZE_PASSTHRU, ce); - - if (ret && incomplete_class) { - php_store_class_name(rval, ZSTR_VAL(class_name), len2); + } else { + if (yych <= 'I') { + if (yych <= '9') goto yy46; + if (yych <= 'H') goto yy18; + goto yy48; + } else { + if (yych == 'N') goto yy49; + goto yy18; } - zend_string_release(class_name); - return ret; } - - elements = object_common1(UNSERIALIZE_PASSTHRU, ce); - - if (elements < 0) { - zend_string_release(class_name); - return 0; + yy26: + yych = *++YYCURSOR; + if (yych <= ',') { + if (yych == '+') goto yy50; + goto yy18; + } else { + if (yych <= '-') goto yy50; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy51; + goto yy18; } - - if (incomplete_class) { - php_store_class_name(rval, ZSTR_VAL(class_name), len2); + yy27: + yych = *++YYCURSOR; + if (yych <= ',') { + if (yych == '+') goto yy53; + goto yy18; + } else { + if (yych <= '-') goto yy53; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy54; + goto yy18; } - zend_string_release(class_name); - - return object_common2(UNSERIALIZE_PASSTHRU, elements); - } - #line 853 "ext/standard/var_unserializer.c" - yy25: + yy28: yych = *++YYCURSOR; if (yych <= ',') { - if (yych != '+') goto yy18; + if (yych == '+') goto yy56; + goto yy18; } else { - if (yych <= '-') goto yy26; + if (yych <= '-') goto yy56; if (yych <= '/') goto yy18; - if (yych <= '9') goto yy27; + if (yych <= '9') goto yy57; goto yy18; } - yy26: + yy29: yych = *++YYCURSOR; + if (yych == '+') goto yy59; if (yych <= '/') goto yy18; - if (yych >= ':') goto yy18; - yy27: + if (yych <= '9') goto yy60; + goto yy18; + yy30: + yych = *++YYCURSOR; + if (yybm[0+yych] & 128) { + goto yy31; + } + goto yy18; + yy31: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; @@@ -1107,7 -897,61 +945,65 @@@ yy59 yych = *++YYCURSOR; if (yych <= '/') goto yy18; if (yych >= ':') goto yy18; - yy61: + yy60: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy60; + if (yych <= ':') goto yy81; + goto yy18; + yy62: + yych = *++YYCURSOR; + if (yych == '"') goto yy82; + goto yy18; + yy63: + ++YYCURSOR; -#line 537 "ext/standard/var_unserializer.re" ++#line 586 "ext/standard/var_unserializer.re" + { - long id; ++ zend_long id; + + *p = YYCURSOR; + if (!var_hash) return 0; + + id = parse_iv(start + 2) - 1; - if (id == -1 || var_access(var_hash, id, &rval_ref) != SUCCESS) { ++ if (id == -1 || (rval_ref = var_access(var_hash, id)) == NULL) { + return 0; + } + - if (*rval != NULL) { - var_push_dtor_no_addref(var_hash, rval); ++ zval_ptr_dtor(rval); ++ if (Z_ISUNDEF_P(rval_ref) || (Z_ISREF_P(rval_ref) && Z_ISUNDEF_P(Z_REFVAL_P(rval_ref)))) { ++ ZVAL_UNDEF(rval); ++ return 1; ++ } ++ if (Z_ISREF_P(rval_ref)) { ++ ZVAL_COPY(rval, rval_ref); ++ } else { ++ ZVAL_NEW_REF(rval_ref, rval_ref); ++ ZVAL_COPY(rval, rval_ref); + } - *rval = *rval_ref; - Z_ADDREF_PP(rval); - Z_SET_ISREF_PP(rval); + + return 1; + } -#line 936 "ext/standard/var_unserializer.c" ++#line 989 "ext/standard/var_unserializer.c" + yy65: + yych = *++YYCURSOR; + if (yych == '"') goto yy84; + goto yy18; + yy66: + yych = *++YYCURSOR; + if (yych == '{') goto yy86; + goto yy18; + yy67: + ++YYCURSOR; -#line 588 "ext/standard/var_unserializer.re" ++#line 643 "ext/standard/var_unserializer.re" + { + *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_BOOL(*rval, parse_iv(start + 2)); ++ ZVAL_BOOL(rval, parse_iv(start + 2)); + return 1; + } -#line 954 "ext/standard/var_unserializer.c" ++#line 1006 "ext/standard/var_unserializer.c" + yy69: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *YYCURSOR; @@@ -1124,123 -968,44 +1020,43 @@@ goto yy18; } } - yy63: + yy71: ++YYCURSOR; - #line 668 "ext/standard/var_unserializer.re" -#line 637 "ext/standard/var_unserializer.re" ++#line 691 "ext/standard/var_unserializer.re" { -#if SIZEOF_LONG == 4 +#if SIZEOF_ZEND_LONG == 4 use_double: #endif *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_DOUBLE(*rval, zend_strtod((const char *)start + 2, NULL)); + ZVAL_DOUBLE(rval, zend_strtod((const char *)start + 2, NULL)); return 1; } - #line 1139 "ext/standard/var_unserializer.c" - yy65: -#line 984 "ext/standard/var_unserializer.c" ++#line 1035 "ext/standard/var_unserializer.c" + yy73: yych = *++YYCURSOR; if (yych <= ',') { - if (yych != '+') goto yy18; + if (yych == '+') goto yy88; + goto yy18; } else { - if (yych <= '-') goto yy66; + if (yych <= '-') goto yy88; if (yych <= '/') goto yy18; - if (yych <= '9') goto yy67; + if (yych <= '9') goto yy89; goto yy18; } - yy66: + yy74: yych = *++YYCURSOR; - if (yych <= ',') { - if (yych == '+') goto yy69; - goto yy18; - } else { - if (yych <= '-') goto yy69; - if (yych <= '/') goto yy18; - if (yych >= ':') goto yy18; - } - yy67: - ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy67; - if (yych == ';') goto yy63; + if (yych == 'F') goto yy91; goto yy18; - yy69: + yy75: yych = *++YYCURSOR; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy67; + if (yych == 'N') goto yy91; goto yy18; - yy70: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); - yych = *YYCURSOR; - if (yych <= ';') { - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy70; - if (yych <= ':') goto yy18; - goto yy63; - } else { - if (yych <= 'E') { - if (yych <= 'D') goto yy18; - goto yy65; - } else { - if (yych == 'e') goto yy65; - goto yy18; - } - } - yy72: - yych = *++YYCURSOR; - if (yych != 'F') goto yy18; - yy73: - yych = *++YYCURSOR; - if (yych != ';') goto yy18; + yy76: ++YYCURSOR; - #line 652 "ext/standard/var_unserializer.re" -#line 595 "ext/standard/var_unserializer.re" ++#line 649 "ext/standard/var_unserializer.re" { - *p = YYCURSOR; - - if (!strncmp((char*)start + 2, "NAN", 3)) { - ZVAL_DOUBLE(rval, php_get_nan()); - } else if (!strncmp((char*)start + 2, "INF", 3)) { - ZVAL_DOUBLE(rval, php_get_inf()); - } else if (!strncmp((char*)start + 2, "-INF", 4)) { - ZVAL_DOUBLE(rval, -php_get_inf()); - } else { - ZVAL_NULL(rval); - } - - return 1; - } - #line 1214 "ext/standard/var_unserializer.c" - yy76: - yych = *++YYCURSOR; - if (yych == 'N') goto yy73; - goto yy18; - yy77: - yych = *++YYCURSOR; - if (yych <= ',') { - if (yych != '+') goto yy18; - } else { - if (yych <= '-') goto yy78; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy79; - goto yy18; - } - yy78: - yych = *++YYCURSOR; - if (yych <= '/') goto yy18; - if (yych >= ':') goto yy18; - yy79: - ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy79; - if (yych != ';') goto yy18; - ++YYCURSOR; - #line 626 "ext/standard/var_unserializer.re" - { - #if SIZEOF_ZEND_LONG == 4 - int digits = YYCURSOR - start - 3; -#if SIZEOF_LONG == 4 ++#if SIZEOF_ZEND_LONG == 4 + int digits = YYCURSOR - start - 3; if (start[2] == '-' || start[2] == '+') { digits--; @@@ -1260,58 -1025,20 +1076,19 @@@ } #endif *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_LONG(*rval, parse_iv(start + 2)); + ZVAL_LONG(rval, parse_iv(start + 2)); return 1; } - #line 1267 "ext/standard/var_unserializer.c" - yy83: - yych = *++YYCURSOR; - if (yych <= '/') goto yy18; - if (yych >= '2') goto yy18; - yych = *++YYCURSOR; - if (yych != ';') goto yy18; - ++YYCURSOR; - #line 620 "ext/standard/var_unserializer.re" - { - *p = YYCURSOR; - ZVAL_BOOL(rval, parse_iv(start + 2)); - return 1; - } - #line 1281 "ext/standard/var_unserializer.c" - yy87: - ++YYCURSOR; - #line 614 "ext/standard/var_unserializer.re" - { - *p = YYCURSOR; - ZVAL_NULL(rval); - return 1; - } - #line 1290 "ext/standard/var_unserializer.c" - yy89: - yych = *++YYCURSOR; - if (yych <= ',') { - if (yych != '+') goto yy18; - } else { - if (yych <= '-') goto yy90; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy91; - goto yy18; - } - yy90: -#line 1033 "ext/standard/var_unserializer.c" ++#line 1083 "ext/standard/var_unserializer.c" + yy78: yych = *++YYCURSOR; - if (yych <= '/') goto yy18; - if (yych >= ':') goto yy18; - yy91: - ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy91; - if (yych != ';') goto yy18; + if (yych == '"') goto yy92; + goto yy18; + yy79: ++YYCURSOR; - #line 589 "ext/standard/var_unserializer.re" -#line 558 "ext/standard/var_unserializer.re" ++#line 612 "ext/standard/var_unserializer.re" { - long id; + zend_long id; *p = YYCURSOR; if (!var_hash) return 0; @@@ -1334,11 -1059,235 +1111,235 @@@ return 1; } -#line 1063 "ext/standard/var_unserializer.c" ++#line 1115 "ext/standard/var_unserializer.c" + yy81: + yych = *++YYCURSOR; + if (yych == '"') goto yy94; + goto yy18; + yy82: + ++YYCURSOR; -#line 749 "ext/standard/var_unserializer.re" ++#line 801 "ext/standard/var_unserializer.re" + { + size_t len, len2, len3, maxlen; - long elements; - char *class_name; ++ zend_long elements; ++ char *str; ++ zend_string *class_name; + zend_class_entry *ce; - zend_class_entry **pce; + int incomplete_class = 0; + + int custom_object = 0; + - zval *user_func; - zval *retval_ptr; - zval **args[1]; - zval *arg_func_name; ++ zval user_func; ++ zval retval; ++ zval args[1]; + + if (!var_hash) return 0; + if (*start == 'C') { + custom_object = 1; + } + - INIT_PZVAL(*rval); + len2 = len = parse_uiv(start + 2); + maxlen = max - YYCURSOR; + if (maxlen < len || len == 0) { + *p = start + 2; + return 0; + } + - class_name = (char*)YYCURSOR; ++ str = (char*)YYCURSOR; + + YYCURSOR += len; + + if (*(YYCURSOR) != '"') { + *p = YYCURSOR; + return 0; + } + if (*(YYCURSOR+1) != ':') { + *p = YYCURSOR+1; + return 0; + } + - len3 = strspn(class_name, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\"); ++ len3 = strspn(str, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\"); + if (len3 != len) + { + *p = YYCURSOR + len3 - len; + return 0; + } + - class_name = estrndup(class_name, len); ++ class_name = zend_string_init(str, len, 0); + + do { ++ if(!unserialize_allowed_class(class_name, classes)) { ++ incomplete_class = 1; ++ ce = PHP_IC_ENTRY; ++ break; ++ } ++ + /* Try to find class directly */ + BG(serialize_lock)++; - if (zend_lookup_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) { ++ ce = zend_lookup_class(class_name); ++ if (ce) { + BG(serialize_lock)--; + if (EG(exception)) { - efree(class_name); ++ zend_string_release(class_name); + return 0; + } - ce = *pce; + break; + } + BG(serialize_lock)--; + + if (EG(exception)) { - efree(class_name); ++ zend_string_release(class_name); + return 0; + } + + /* Check for unserialize callback */ + if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) { + incomplete_class = 1; + ce = PHP_IC_ENTRY; + break; + } + + /* Call unserialize callback */ - MAKE_STD_ZVAL(user_func); - ZVAL_STRING(user_func, PG(unserialize_callback_func), 1); - args[0] = &arg_func_name; - MAKE_STD_ZVAL(arg_func_name); - ZVAL_STRING(arg_func_name, class_name, 1); ++ ZVAL_STRING(&user_func, PG(unserialize_callback_func)); ++ ++ ZVAL_STR_COPY(&args[0], class_name); + BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) { ++ if (call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL) != SUCCESS) { + BG(serialize_lock)--; + if (EG(exception)) { - efree(class_name); ++ zend_string_release(class_name); + zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); ++ zval_ptr_dtor(&args[0]); + return 0; + } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "defined (%s) but not found", user_func->value.str.val); ++ php_error_docref(NULL, E_WARNING, "defined (%s) but not found", Z_STRVAL(user_func)); + incomplete_class = 1; + ce = PHP_IC_ENTRY; + zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); ++ zval_ptr_dtor(&args[0]); + break; + } + BG(serialize_lock)--; - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } ++ zval_ptr_dtor(&retval); + if (EG(exception)) { - efree(class_name); ++ zend_string_release(class_name); + zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); ++ zval_ptr_dtor(&args[0]); + return 0; + } + + /* The callback function may have defined the class */ + BG(serialize_lock)++; - if (zend_lookup_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) { - ce = *pce; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function %s() hasn't defined the class it was called for", user_func->value.str.val); ++ if ((ce = zend_lookup_class(class_name)) == NULL) { ++ php_error_docref(NULL, E_WARNING, "Function %s() hasn't defined the class it was called for", Z_STRVAL(user_func)); + incomplete_class = 1; + ce = PHP_IC_ENTRY; + } + BG(serialize_lock)--; + + zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); ++ zval_ptr_dtor(&args[0]); + break; + } while (1); + + *p = YYCURSOR; + + if (custom_object) { + int ret; + + ret = object_custom(UNSERIALIZE_PASSTHRU, ce); + + if (ret && incomplete_class) { - php_store_class_name(*rval, class_name, len2); ++ php_store_class_name(rval, ZSTR_VAL(class_name), len2); + } - efree(class_name); ++ zend_string_release(class_name); + return ret; + } + + elements = object_common1(UNSERIALIZE_PASSTHRU, ce); + + if (elements < 0) { - efree(class_name); ++ zend_string_release(class_name); + return 0; + } + + if (incomplete_class) { - php_store_class_name(*rval, class_name, len2); ++ php_store_class_name(rval, ZSTR_VAL(class_name), len2); + } - efree(class_name); ++ zend_string_release(class_name); + + return object_common2(UNSERIALIZE_PASSTHRU, elements); + } -#line 1224 "ext/standard/var_unserializer.c" ++#line 1274 "ext/standard/var_unserializer.c" + yy84: + ++YYCURSOR; -#line 680 "ext/standard/var_unserializer.re" ++#line 732 "ext/standard/var_unserializer.re" + { + size_t len, maxlen; - char *str; ++ zend_string *str; + + len = parse_uiv(start + 2); + maxlen = max - YYCURSOR; + if (maxlen < len) { + *p = start + 2; + return 0; + } + - if ((str = unserialize_str(&YYCURSOR, &len, maxlen)) == NULL) { ++ if ((str = unserialize_str(&YYCURSOR, len, maxlen)) == NULL) { + return 0; + } + + if (*(YYCURSOR) != '"') { - efree(str); ++ zend_string_free(str); + *p = YYCURSOR; + return 0; + } + + if (*(YYCURSOR + 1) != ';') { + efree(str); + *p = YYCURSOR + 1; + return 0; + } + + YYCURSOR += 2; + *p = YYCURSOR; + - INIT_PZVAL(*rval); - ZVAL_STRINGL(*rval, str, len, 0); ++ ZVAL_STR(rval, str); + return 1; + } -#line 1262 "ext/standard/var_unserializer.c" ++#line 1311 "ext/standard/var_unserializer.c" + yy86: + ++YYCURSOR; -#line 715 "ext/standard/var_unserializer.re" ++#line 766 "ext/standard/var_unserializer.re" + { - long elements = parse_iv(start + 2); ++ zend_long elements = parse_iv(start + 2); + /* use iv() not uiv() in order to check data range */ + *p = YYCURSOR; + if (!var_hash) return 0; + + if (elements < 0) { + return 0; + } + - INIT_PZVAL(*rval); - - array_init_size(*rval, elements); ++ array_init_size(rval, elements); ++ if (elements) { ++ /* we can't convert from packed to hash during unserialization, because ++ reference to some zvals might be keept in var_hash (to support references) */ ++ zend_hash_real_init(Z_ARRVAL_P(rval), 0); ++ } + - if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_PP(rval), elements, 0)) { ++ if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_P(rval), elements, 0)) { + return 0; + } + + return finish_nested_data(UNSERIALIZE_PASSTHRU); + } -#line 1286 "ext/standard/var_unserializer.c" +#line 1338 "ext/standard/var_unserializer.c" - yy95: + yy88: yych = *++YYCURSOR; if (yych <= ',') { - if (yych != '+') goto yy18; + if (yych == '+') goto yy96; + goto yy18; } else { if (yych <= '-') goto yy96; if (yych <= '/') goto yy18; @@@ -1354,38 -1298,90 +1350,88 @@@ yy89 if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; if (yych <= '/') goto yy18; - if (yych <= '9') goto yy97; - if (yych != ';') goto yy18; + if (yych <= '9') goto yy89; + if (yych == ';') goto yy71; + goto yy18; + yy91: + yych = *++YYCURSOR; + if (yych == ';') goto yy97; + goto yy18; + yy92: ++YYCURSOR; - #line 563 "ext/standard/var_unserializer.re" -#line 736 "ext/standard/var_unserializer.re" ++#line 790 "ext/standard/var_unserializer.re" { - zend_long id; + long elements; + if (!var_hash) return 0; - *p = YYCURSOR; - if (!var_hash) return 0; - INIT_PZVAL(*rval); - + elements = object_common1(UNSERIALIZE_PASSTHRU, ZEND_STANDARD_CLASS_DEF_PTR); + if (elements < 0) { + return 0; + } + return object_common2(UNSERIALIZE_PASSTHRU, elements); + } -#line 1324 "ext/standard/var_unserializer.c" ++#line 1374 "ext/standard/var_unserializer.c" + yy94: + ++YYCURSOR; -#line 647 "ext/standard/var_unserializer.re" ++#line 700 "ext/standard/var_unserializer.re" + { + size_t len, maxlen; + char *str; - id = parse_iv(start + 2) - 1; - if (id == -1 || (rval_ref = var_access(var_hash, id)) == NULL) { + len = parse_uiv(start + 2); + maxlen = max - YYCURSOR; + if (maxlen < len) { + *p = start + 2; return 0; } - zval_ptr_dtor(rval); - if (Z_ISUNDEF_P(rval_ref) || (Z_ISREF_P(rval_ref) && Z_ISUNDEF_P(Z_REFVAL_P(rval_ref)))) { - ZVAL_UNDEF(rval); - return 1; + str = (char*)YYCURSOR; + + YYCURSOR += len; + + if (*(YYCURSOR) != '"') { + *p = YYCURSOR; + return 0; } - if (Z_ISREF_P(rval_ref)) { - ZVAL_COPY(rval, rval_ref); + + if (*(YYCURSOR + 1) != ';') { + *p = YYCURSOR + 1; + return 0; + } + + YYCURSOR += 2; + *p = YYCURSOR; + - INIT_PZVAL(*rval); - ZVAL_STRINGL(*rval, str, len, 1); ++ ZVAL_STRINGL(rval, str, len); + return 1; + } -#line 1360 "ext/standard/var_unserializer.c" ++#line 1409 "ext/standard/var_unserializer.c" + yy96: + yych = *++YYCURSOR; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy89; + goto yy18; + yy97: + ++YYCURSOR; -#line 622 "ext/standard/var_unserializer.re" ++#line 675 "ext/standard/var_unserializer.re" + { + *p = YYCURSOR; - INIT_PZVAL(*rval); + - if (!strncmp(start + 2, "NAN", 3)) { - ZVAL_DOUBLE(*rval, php_get_nan()); - } else if (!strncmp(start + 2, "INF", 3)) { - ZVAL_DOUBLE(*rval, php_get_inf()); - } else if (!strncmp(start + 2, "-INF", 4)) { - ZVAL_DOUBLE(*rval, -php_get_inf()); ++ if (!strncmp((char*)start + 2, "NAN", 3)) { ++ ZVAL_DOUBLE(rval, php_get_nan()); ++ } else if (!strncmp((char*)start + 2, "INF", 3)) { ++ ZVAL_DOUBLE(rval, php_get_inf()); ++ } else if (!strncmp((char*)start + 2, "-INF", 4)) { ++ ZVAL_DOUBLE(rval, -php_get_inf()); + } else { - ZVAL_NEW_REF(rval_ref, rval_ref); - ZVAL_COPY(rval, rval_ref); ++ ZVAL_NULL(rval); } return 1; } - #line 1387 "ext/standard/var_unserializer.c" -#line 1383 "ext/standard/var_unserializer.c" ++#line 1433 "ext/standard/var_unserializer.c" } - #line 938 "ext/standard/var_unserializer.re" -#line 911 "ext/standard/var_unserializer.re" ++#line 961 "ext/standard/var_unserializer.re" return 0; diff --cc ext/standard/var_unserializer.re index 9e6bb5d,bb0000b..b5f459a --- a/ext/standard/var_unserializer.re +++ b/ext/standard/var_unserializer.re @@@ -26,9 -26,14 +26,12 @@@ #define VAR_ENTRIES_MAX 1024 #define VAR_ENTRIES_DBG 0 ++/* VAR_FLAG used in var_dtor entries to signify an entry on which __wakeup should be called */ + #define VAR_WAKEUP_FLAG 1 -#define WITH_WAKEUP_FLAG(zv_ptr) ((zval *) ((zend_uintptr_t) zv_ptr | VAR_WAKEUP_FLAG)) -#define WITHOUT_WAKEUP_FLAG(zv_ptr) ((zval *) ((zend_uintptr_t) zv_ptr & ~VAR_WAKEUP_FLAG)) -#define HAS_WAKEUP_FLAG(zv_ptr) ((zend_uintptr_t) zv_ptr & VAR_WAKEUP_FLAG) + typedef struct { zval *data[VAR_ENTRIES_MAX]; - long used_slots; + zend_long used_slots; void *next; } var_entries; @@@ -80,29 -107,33 +83,30 @@@ PHPAPI zval *var_tmp_var(php_unserializ } var_hash = (*var_hashx)->last_dtor; -#if VAR_ENTRIES_DBG - fprintf(stderr, "var_push_dtor_no_addref(%p, %ld): %d (%d)\n", *rval, var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(rval), Z_REFCOUNT_PP(rval)); -#endif - - if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) { - var_hash = emalloc(sizeof(var_entries)); - var_hash->used_slots = 0; - var_hash->next = 0; - - if (!(*var_hashx)->first_dtor) { - (*var_hashx)->first_dtor = var_hash; - } else { - ((var_entries *) (*var_hashx)->last_dtor)->next = var_hash; - } - - (*var_hashx)->last_dtor = var_hash; - } - - var_hash->data[var_hash->used_slots++] = *rval; + if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) { + var_hash = emalloc(sizeof(var_dtor_entries)); + var_hash->used_slots = 0; + var_hash->next = 0; + + if (!(*var_hashx)->first_dtor) { + (*var_hashx)->first_dtor = var_hash; + } else { + ((var_dtor_entries *) (*var_hashx)->last_dtor)->next = var_hash; + } + + (*var_hashx)->last_dtor = var_hash; + } + ZVAL_UNDEF(&var_hash->data[var_hash->used_slots]); ++ Z_VAR_FLAGS(var_hash->data[var_hash->used_slots]) = 0; + return &var_hash->data[var_hash->used_slots++]; } -PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval) +PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval *nzval) { - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; #if VAR_ENTRIES_DBG - fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(nzval)); + fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_P(nzval)); #endif while (var_hash) { @@@ -138,9 -171,11 +142,13 @@@ static zval *var_access(php_unserialize PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) { void *next; - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; + var_dtor_entries *var_dtor_hash = (*var_hashx)->first_dtor; + zend_bool wakeup_failed = 0; - TSRMLS_FETCH(); ++ zval wakeup_name; ++ ZVAL_UNDEF(&wakeup_name); + #if VAR_ENTRIES_DBG fprintf(stderr, "var_destroy(%ld)\n", var_hash?var_hash->used_slots:-1L); #endif @@@ -151,17 -186,44 +159,42 @@@ var_hash = next; } - var_hash = (*var_hashx)->first_dtor; - - while (var_hash) { - for (i = 0; i < var_hash->used_slots; i++) { - zval *zv = var_hash->data[i]; + while (var_dtor_hash) { + for (i = 0; i < var_dtor_hash->used_slots; i++) { ++ zval *zv = &var_dtor_hash->data[i]; #if VAR_ENTRIES_DBG - fprintf(stderr, "var_destroy dtor(%p, %ld)\n", var_hash->data[i], Z_REFCOUNT_P(var_hash->data[i])); + fprintf(stderr, "var_destroy dtor(%p, %ld)\n", var_dtor_hash->data[i], Z_REFCOUNT_P(var_dtor_hash->data[i])); #endif - zval_ptr_dtor(&var_dtor_hash->data[i]); + - if (HAS_WAKEUP_FLAG(zv)) { - zv = WITHOUT_WAKEUP_FLAG(zv); ++ /* Perform delayed __wakeup calls */ ++ if (Z_VAR_FLAGS_P(zv) == VAR_WAKEUP_FLAG) { + if (!wakeup_failed) { - zval *retval_ptr = NULL; - zval wakeup_name; - INIT_PZVAL(&wakeup_name); - ZVAL_STRINGL(&wakeup_name, "__wakeup", sizeof("__wakeup") - 1, 0); ++ zval retval; ++ if (Z_ISUNDEF(wakeup_name)) { ++ ZVAL_STRINGL(&wakeup_name, "__wakeup", sizeof("__wakeup") - 1); ++ } + + BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), &zv, &wakeup_name, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC) == FAILURE || retval_ptr == NULL) { ++ if (call_user_function_ex(CG(function_table), zv, &wakeup_name, &retval, 0, 0, 1, NULL) == FAILURE || Z_ISUNDEF(retval)) { + wakeup_failed = 1; - zend_object_store_ctor_failed(zv TSRMLS_CC); ++ GC_FLAGS(Z_OBJ_P(zv)) |= IS_OBJ_DESTRUCTOR_CALLED; + } + BG(serialize_lock)--; + - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } ++ zval_ptr_dtor(&retval); + } else { - zend_object_store_ctor_failed(zv TSRMLS_CC); ++ GC_FLAGS(Z_OBJ_P(zv)) |= IS_OBJ_DESTRUCTOR_CALLED; + } + } + - zval_ptr_dtor(&zv); ++ zval_ptr_dtor(zv); } - next = var_hash->next; - efree(var_hash); - var_hash = next; + next = var_dtor_hash->next; + efree_size(var_dtor_hash, sizeof(var_dtor_entries)); + var_dtor_hash = next; } ++ ++ zval_ptr_dtor(&wakeup_name); } /* }}} */ @@@ -461,14 -472,9 +494,12 @@@ static inline zend_long object_common1( #ifdef PHP_WIN32 # pragma optimize("", off) #endif -static inline int object_common2(UNSERIALIZE_PARAMETER, long elements) +static inline int object_common2(UNSERIALIZE_PARAMETER, zend_long elements) { - zval retval; - zval fname; - if (Z_TYPE_PP(rval) != IS_OBJECT) { + HashTable *ht; + zend_bool has_wakeup; + + if (Z_TYPE_P(rval) != IS_OBJECT) { return 0; } @@@ -485,20 -487,22 +516,12 @@@ return 0; } - if (Z_TYPE_PP(rval) != IS_OBJECT) { - return 0; - } - - if (Z_OBJCE_PP(rval) != PHP_IC_ENTRY && - zend_hash_exists(&Z_OBJCE_PP(rval)->function_table, "__wakeup", sizeof("__wakeup")) - ) { - /* Store object for delayed __wakeup call. Remove references. */ - zval **slot = get_var_push_dtor_slot(var_hash); - zval *zv = *rval; - Z_ADDREF_P(zv); - if (PZVAL_IS_REF(zv)) { - SEPARATE_ZVAL(&zv); - } - *slot = WITH_WAKEUP_FLAG(zv); + ZVAL_DEREF(rval); + if (has_wakeup) { - ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1); - BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), rval, &fname, &retval, 0, 0, 1, NULL) == FAILURE || Z_ISUNDEF(retval)) { - GC_FLAGS(Z_OBJ_P(rval)) |= IS_OBJ_DESTRUCTOR_CALLED; - } - BG(serialize_lock)--; - zval_dtor(&fname); - zval_dtor(&retval); - } - - if (EG(exception)) { - return 0; ++ /* Delay __wakeup call until end of serialization */ ++ zval *wakeup_var = var_tmp_var(var_hash); ++ ZVAL_COPY(wakeup_var, rval); ++ Z_VAR_FLAGS_P(wakeup_var) = VAR_WAKEUP_FLAG; } return finish_nested_data(UNSERIALIZE_PASSTHRU);
diff --cc ext/standard/tests/serialize/bug70963.phpt index 93843c6,0000000..0bdfb2c mode 100644,000000..100644 --- a/ext/standard/tests/serialize/bug70963.phpt +++ b/ext/standard/tests/serialize/bug70963.phpt @@@ -1,42 -1,0 +1,46 @@@ +--TEST-- +Bug #70963 (Unserialize shows UNKNOW in result) +--FILE-- +<?php +var_dump(unserialize('a:2:{i:0;O:9:"exception":1:{s:16:"'."\0".'Exception'."\0".'trace";s:4:"test";}i:1;R:3;}')); +var_dump(unserialize('a:2:{i:0;O:9:"exception":1:{s:16:"'."\0".'Exception'."\0".'trace";s:4:"test";}i:1;r:3;}')); +?> +--EXPECTF-- - array(1) { ++array(2) { + [0]=> + object(Exception)#%d (6) { + ["message":protected]=> + string(0) "" + ["string":"Exception":private]=> + string(0) "" + ["code":protected]=> + int(0) + ["file":protected]=> + string(%d) "%s" + ["line":protected]=> + int(2) + ["previous":"Exception":private]=> + NULL + } ++ [1]=> ++ string(4) "test" +} - array(1) { ++array(2) { + [0]=> + object(Exception)#%d (6) { + ["message":protected]=> + string(0) "" + ["string":"Exception":private]=> + string(0) "" + ["code":protected]=> + int(0) + ["file":protected]=> + string(%d) "%s" + ["line":protected]=> + int(3) + ["previous":"Exception":private]=> + NULL + } ++ [1]=> ++ string(4) "test" +} diff --cc ext/standard/var_unserializer.c index 0b1de2c,6706866..76688b9 --- a/ext/standard/var_unserializer.c +++ b/ext/standard/var_unserializer.c @@@ -28,9 -28,14 +28,12 @@@ #define VAR_ENTRIES_MAX 1024 #define VAR_ENTRIES_DBG 0 ++/* VAR_FLAG used in var_dtor entries to signify an entry on which __wakeup should be called */ + #define VAR_WAKEUP_FLAG 1 -#define WITH_WAKEUP_FLAG(zv_ptr) ((zval *) ((zend_uintptr_t) zv_ptr | VAR_WAKEUP_FLAG)) -#define WITHOUT_WAKEUP_FLAG(zv_ptr) ((zval *) ((zend_uintptr_t) zv_ptr & ~VAR_WAKEUP_FLAG)) -#define HAS_WAKEUP_FLAG(zv_ptr) ((zend_uintptr_t) zv_ptr & VAR_WAKEUP_FLAG) + typedef struct { zval *data[VAR_ENTRIES_MAX]; - long used_slots; + zend_long used_slots; void *next; } var_entries; @@@ -82,29 -109,33 +85,30 @@@ PHPAPI zval *var_tmp_var(php_unserializ } var_hash = (*var_hashx)->last_dtor; -#if VAR_ENTRIES_DBG - fprintf(stderr, "var_push_dtor_no_addref(%p, %ld): %d (%d)\n", *rval, var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(rval), Z_REFCOUNT_PP(rval)); -#endif - - if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) { - var_hash = emalloc(sizeof(var_entries)); - var_hash->used_slots = 0; - var_hash->next = 0; - - if (!(*var_hashx)->first_dtor) { - (*var_hashx)->first_dtor = var_hash; - } else { - ((var_entries *) (*var_hashx)->last_dtor)->next = var_hash; - } - - (*var_hashx)->last_dtor = var_hash; - } - - var_hash->data[var_hash->used_slots++] = *rval; + if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) { + var_hash = emalloc(sizeof(var_dtor_entries)); + var_hash->used_slots = 0; + var_hash->next = 0; + + if (!(*var_hashx)->first_dtor) { + (*var_hashx)->first_dtor = var_hash; + } else { + ((var_dtor_entries *) (*var_hashx)->last_dtor)->next = var_hash; + } + + (*var_hashx)->last_dtor = var_hash; + } + ZVAL_UNDEF(&var_hash->data[var_hash->used_slots]); ++ Z_VAR_FLAGS(var_hash->data[var_hash->used_slots]) = 0; + return &var_hash->data[var_hash->used_slots++]; } -PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval) +PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval *nzval) { - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; #if VAR_ENTRIES_DBG - fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(nzval)); + fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_P(nzval)); #endif while (var_hash) { @@@ -140,9 -173,11 +144,13 @@@ static zval *var_access(php_unserialize PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) { void *next; - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; + var_dtor_entries *var_dtor_hash = (*var_hashx)->first_dtor; + zend_bool wakeup_failed = 0; - TSRMLS_FETCH(); ++ zval wakeup_name; ++ ZVAL_UNDEF(&wakeup_name); + #if VAR_ENTRIES_DBG fprintf(stderr, "var_destroy(%ld)\n", var_hash?var_hash->used_slots:-1L); #endif @@@ -153,17 -188,44 +161,42 @@@ var_hash = next; } - var_hash = (*var_hashx)->first_dtor; - - while (var_hash) { - for (i = 0; i < var_hash->used_slots; i++) { - zval *zv = var_hash->data[i]; + while (var_dtor_hash) { + for (i = 0; i < var_dtor_hash->used_slots; i++) { ++ zval *zv = &var_dtor_hash->data[i]; #if VAR_ENTRIES_DBG - fprintf(stderr, "var_destroy dtor(%p, %ld)\n", var_hash->data[i], Z_REFCOUNT_P(var_hash->data[i])); + fprintf(stderr, "var_destroy dtor(%p, %ld)\n", var_dtor_hash->data[i], Z_REFCOUNT_P(var_dtor_hash->data[i])); #endif - zval_ptr_dtor(&var_dtor_hash->data[i]); + - if (HAS_WAKEUP_FLAG(zv)) { - zv = WITHOUT_WAKEUP_FLAG(zv); ++ /* Perform delayed __wakeup calls */ ++ if (Z_VAR_FLAGS_P(zv) == VAR_WAKEUP_FLAG) { + if (!wakeup_failed) { - zval *retval_ptr = NULL; - zval wakeup_name; - INIT_PZVAL(&wakeup_name); - ZVAL_STRINGL(&wakeup_name, "__wakeup", sizeof("__wakeup") - 1, 0); ++ zval retval; ++ if (Z_ISUNDEF(wakeup_name)) { ++ ZVAL_STRINGL(&wakeup_name, "__wakeup", sizeof("__wakeup") - 1); ++ } + + BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), &zv, &wakeup_name, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC) == FAILURE || retval_ptr == NULL) { ++ if (call_user_function_ex(CG(function_table), zv, &wakeup_name, &retval, 0, 0, 1, NULL) == FAILURE || Z_ISUNDEF(retval)) { + wakeup_failed = 1; - zend_object_store_ctor_failed(zv TSRMLS_CC); ++ GC_FLAGS(Z_OBJ_P(zv)) |= IS_OBJ_DESTRUCTOR_CALLED; + } + BG(serialize_lock)--; + - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } ++ zval_ptr_dtor(&retval); + } else { - zend_object_store_ctor_failed(zv TSRMLS_CC); ++ GC_FLAGS(Z_OBJ_P(zv)) |= IS_OBJ_DESTRUCTOR_CALLED; + } + } + - zval_ptr_dtor(&zv); ++ zval_ptr_dtor(zv); } - next = var_hash->next; - efree(var_hash); - var_hash = next; + next = var_dtor_hash->next; + efree_size(var_dtor_hash, sizeof(var_dtor_entries)); + var_dtor_hash = next; } ++ ++ zval_ptr_dtor(&wakeup_name); } /* }}} */ @@@ -238,7 -280,7 +271,7 @@@ static inline int unserialize_allowed_c #define YYMARKER marker - #line 246 "ext/standard/var_unserializer.re" -#line 288 "ext/standard/var_unserializer.re" ++#line 279 "ext/standard/var_unserializer.re" @@@ -457,14 -468,9 +490,12 @@@ static inline zend_long object_common1( #ifdef PHP_WIN32 # pragma optimize("", off) #endif -static inline int object_common2(UNSERIALIZE_PARAMETER, long elements) +static inline int object_common2(UNSERIALIZE_PARAMETER, zend_long elements) { - zval retval; - zval fname; - if (Z_TYPE_PP(rval) != IS_OBJECT) { + HashTable *ht; + zend_bool has_wakeup; + + if (Z_TYPE_P(rval) != IS_OBJECT) { return 0; } @@@ -481,20 -483,22 +512,12 @@@ return 0; } - if (Z_TYPE_PP(rval) != IS_OBJECT) { - return 0; - } - - if (Z_OBJCE_PP(rval) != PHP_IC_ENTRY && - zend_hash_exists(&Z_OBJCE_PP(rval)->function_table, "__wakeup", sizeof("__wakeup")) - ) { - /* Store object for delayed __wakeup call. Remove references. */ - zval **slot = get_var_push_dtor_slot(var_hash); - zval *zv = *rval; - Z_ADDREF_P(zv); - if (PZVAL_IS_REF(zv)) { - SEPARATE_ZVAL(&zv); - } - *slot = WITH_WAKEUP_FLAG(zv); + ZVAL_DEREF(rval); + if (has_wakeup) { - ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1); - BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), rval, &fname, &retval, 0, 0, 1, NULL) == FAILURE || Z_ISUNDEF(retval)) { - GC_FLAGS(Z_OBJ_P(rval)) |= IS_OBJ_DESTRUCTOR_CALLED; - } - BG(serialize_lock)--; - zval_dtor(&fname); - zval_dtor(&retval); - } - - if (EG(exception)) { - return 0; ++ /* Delay __wakeup call until end of serialization */ ++ zval *wakeup_var = var_tmp_var(var_hash); ++ ZVAL_COPY(wakeup_var, rval); ++ Z_VAR_FLAGS_P(wakeup_var) = VAR_WAKEUP_FLAG; } return finish_nested_data(UNSERIALIZE_PASSTHRU); @@@ -555,7 -527,9 +578,7 @@@ static int php_var_unserialize_internal start = cursor; - #line 559 "ext/standard/var_unserializer.c" - - -#line 533 "ext/standard/var_unserializer.c" ++#line 582 "ext/standard/var_unserializer.c" { YYCTYPE yych; static const unsigned char yybm[] = { @@@ -597,30 -570,29 +619,29 @@@ yych = *YYCURSOR; switch (yych) { case 'C': - case 'O': goto yy13; + case 'O': goto yy4; case 'N': goto yy5; - case 'R': goto yy2; - case 'S': goto yy10; - case 'a': goto yy11; - case 'b': goto yy6; - case 'd': goto yy8; - case 'i': goto yy7; + case 'R': goto yy6; + case 'S': goto yy7; + case 'a': goto yy8; + case 'b': goto yy9; + case 'd': goto yy10; + case 'i': goto yy11; case 'o': goto yy12; - case 'r': goto yy4; - case 's': goto yy9; - case '}': goto yy14; - default: goto yy16; + case 'r': goto yy13; + case 's': goto yy14; + case '}': goto yy15; + default: goto yy2; } yy2: - yych = *(YYMARKER = ++YYCURSOR); - if (yych == ':') goto yy95; + ++YYCURSOR; yy3: - #line 936 "ext/standard/var_unserializer.re" -#line 909 "ext/standard/var_unserializer.re" ++#line 959 "ext/standard/var_unserializer.re" { return 0; } - #line 621 "ext/standard/var_unserializer.c" -#line 593 "ext/standard/var_unserializer.c" ++#line 642 "ext/standard/var_unserializer.c" yy4: yych = *(YYMARKER = ++YYCURSOR); - if (yych == ':') goto yy89; + if (yych == ':') goto yy17; goto yy3; yy5: yych = *++YYCURSOR; @@@ -656,20 -628,21 +677,21 @@@ yy12 goto yy3; yy13: yych = *(YYMARKER = ++YYCURSOR); - if (yych == ':') goto yy17; + if (yych == ':') goto yy28; goto yy3; yy14: + yych = *(YYMARKER = ++YYCURSOR); + if (yych == ':') goto yy29; + goto yy3; + yy15: ++YYCURSOR; - #line 930 "ext/standard/var_unserializer.re" -#line 903 "ext/standard/var_unserializer.re" ++#line 953 "ext/standard/var_unserializer.re" { /* this is the case where we have less data than planned */ - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unexpected end of serialized data"); + php_error_docref(NULL, E_NOTICE, "Unexpected end of serialized data"); return 0; /* not sure if it should be 0 or 1 here? */ } - #line 670 "ext/standard/var_unserializer.c" - yy16: - yych = *++YYCURSOR; - goto yy3; -#line 646 "ext/standard/var_unserializer.c" ++#line 695 "ext/standard/var_unserializer.c" yy17: yych = *++YYCURSOR; if (yybm[0+yych] & 128) { @@@ -680,191 -653,110 +702,109 @@@ yy18 YYCURSOR = YYMARKER; goto yy3; yy19: + ++YYCURSOR; -#line 581 "ext/standard/var_unserializer.re" ++#line 637 "ext/standard/var_unserializer.re" + { + *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_NULL(*rval); ++ ZVAL_NULL(rval); + return 1; + } -#line 665 "ext/standard/var_unserializer.c" ++#line 713 "ext/standard/var_unserializer.c" + yy21: yych = *++YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy20; + if (yych <= ',') { + if (yych == '+') goto yy33; + goto yy18; + } else { + if (yych <= '-') goto yy33; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy34; + goto yy18; } + yy22: + yych = *++YYCURSOR; + if (yych == '+') goto yy36; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy37; goto yy18; - yy20: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); - yych = *YYCURSOR; - if (yybm[0+yych] & 128) { - goto yy20; - } + yy23: + yych = *++YYCURSOR; + if (yych == '+') goto yy39; if (yych <= '/') goto yy18; - if (yych >= ';') goto yy18; + if (yych <= '9') goto yy40; + goto yy18; + yy24: yych = *++YYCURSOR; - if (yych != '"') goto yy18; - ++YYCURSOR; - #line 778 "ext/standard/var_unserializer.re" - { - size_t len, len2, len3, maxlen; - zend_long elements; - char *str; - zend_string *class_name; - zend_class_entry *ce; - int incomplete_class = 0; - - int custom_object = 0; - - zval user_func; - zval retval; - zval args[1]; - - if (!var_hash) return 0; - if (*start == 'C') { - custom_object = 1; - } - - len2 = len = parse_uiv(start + 2); - maxlen = max - YYCURSOR; - if (maxlen < len || len == 0) { - *p = start + 2; - return 0; - } - - str = (char*)YYCURSOR; - - YYCURSOR += len; - - if (*(YYCURSOR) != '"') { - *p = YYCURSOR; - return 0; - } - if (*(YYCURSOR+1) != ':') { - *p = YYCURSOR+1; - return 0; - } - - len3 = strspn(str, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\"); - if (len3 != len) - { - *p = YYCURSOR + len3 - len; - return 0; - } - - class_name = zend_string_init(str, len, 0); - - do { - if(!unserialize_allowed_class(class_name, classes)) { - incomplete_class = 1; - ce = PHP_IC_ENTRY; - break; - } - - /* Try to find class directly */ - BG(serialize_lock)++; - ce = zend_lookup_class(class_name); - if (ce) { - BG(serialize_lock)--; - if (EG(exception)) { - zend_string_release(class_name); - return 0; - } - break; - } - BG(serialize_lock)--; - - if (EG(exception)) { - zend_string_release(class_name); - return 0; - } - - /* Check for unserialize callback */ - if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) { - incomplete_class = 1; - ce = PHP_IC_ENTRY; - break; - } - - /* Call unserialize callback */ - ZVAL_STRING(&user_func, PG(unserialize_callback_func)); - - ZVAL_STR_COPY(&args[0], class_name); - BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL) != SUCCESS) { - BG(serialize_lock)--; - if (EG(exception)) { - zend_string_release(class_name); - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&args[0]); - return 0; - } - php_error_docref(NULL, E_WARNING, "defined (%s) but not found", Z_STRVAL(user_func)); - incomplete_class = 1; - ce = PHP_IC_ENTRY; - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&args[0]); - break; - } - BG(serialize_lock)--; - zval_ptr_dtor(&retval); - if (EG(exception)) { - zend_string_release(class_name); - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&args[0]); - return 0; - } - - /* The callback function may have defined the class */ - BG(serialize_lock)++; - if ((ce = zend_lookup_class(class_name)) == NULL) { - php_error_docref(NULL, E_WARNING, "Function %s() hasn't defined the class it was called for", Z_STRVAL(user_func)); - incomplete_class = 1; - ce = PHP_IC_ENTRY; + if (yych <= '/') goto yy18; + if (yych <= '1') goto yy42; + goto yy18; + yy25: + yych = *++YYCURSOR; + if (yych <= '/') { + if (yych <= ',') { + if (yych == '+') goto yy43; + goto yy18; + } else { + if (yych <= '-') goto yy44; + if (yych <= '.') goto yy45; + goto yy18; } - BG(serialize_lock)--; - - zval_ptr_dtor(&user_func); - zval_ptr_dtor(&args[0]); - break; - } while (1); - - *p = YYCURSOR; - - if (custom_object) { - int ret; - - ret = object_custom(UNSERIALIZE_PASSTHRU, ce); - - if (ret && incomplete_class) { - php_store_class_name(rval, ZSTR_VAL(class_name), len2); + } else { + if (yych <= 'I') { + if (yych <= '9') goto yy46; + if (yych <= 'H') goto yy18; + goto yy48; + } else { + if (yych == 'N') goto yy49; + goto yy18; } - zend_string_release(class_name); - return ret; } - - elements = object_common1(UNSERIALIZE_PASSTHRU, ce); - - if (elements < 0) { - zend_string_release(class_name); - return 0; + yy26: + yych = *++YYCURSOR; + if (yych <= ',') { + if (yych == '+') goto yy50; + goto yy18; + } else { + if (yych <= '-') goto yy50; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy51; + goto yy18; } - - if (incomplete_class) { - php_store_class_name(rval, ZSTR_VAL(class_name), len2); + yy27: + yych = *++YYCURSOR; + if (yych <= ',') { + if (yych == '+') goto yy53; + goto yy18; + } else { + if (yych <= '-') goto yy53; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy54; + goto yy18; } - zend_string_release(class_name); - - return object_common2(UNSERIALIZE_PASSTHRU, elements); - } - #line 853 "ext/standard/var_unserializer.c" - yy25: + yy28: yych = *++YYCURSOR; if (yych <= ',') { - if (yych != '+') goto yy18; + if (yych == '+') goto yy56; + goto yy18; } else { - if (yych <= '-') goto yy26; + if (yych <= '-') goto yy56; if (yych <= '/') goto yy18; - if (yych <= '9') goto yy27; + if (yych <= '9') goto yy57; goto yy18; } - yy26: + yy29: yych = *++YYCURSOR; + if (yych == '+') goto yy59; if (yych <= '/') goto yy18; - if (yych >= ':') goto yy18; - yy27: + if (yych <= '9') goto yy60; + goto yy18; + yy30: + yych = *++YYCURSOR; + if (yybm[0+yych] & 128) { + goto yy31; + } + goto yy18; + yy31: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; @@@ -1107,7 -897,61 +945,65 @@@ yy59 yych = *++YYCURSOR; if (yych <= '/') goto yy18; if (yych >= ':') goto yy18; - yy61: + yy60: + ++YYCURSOR; + if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); + yych = *YYCURSOR; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy60; + if (yych <= ':') goto yy81; + goto yy18; + yy62: + yych = *++YYCURSOR; + if (yych == '"') goto yy82; + goto yy18; + yy63: + ++YYCURSOR; -#line 537 "ext/standard/var_unserializer.re" ++#line 586 "ext/standard/var_unserializer.re" + { - long id; ++ zend_long id; + + *p = YYCURSOR; + if (!var_hash) return 0; + + id = parse_iv(start + 2) - 1; - if (id == -1 || var_access(var_hash, id, &rval_ref) != SUCCESS) { ++ if (id == -1 || (rval_ref = var_access(var_hash, id)) == NULL) { + return 0; + } + - if (*rval != NULL) { - var_push_dtor_no_addref(var_hash, rval); ++ zval_ptr_dtor(rval); ++ if (Z_ISUNDEF_P(rval_ref) || (Z_ISREF_P(rval_ref) && Z_ISUNDEF_P(Z_REFVAL_P(rval_ref)))) { ++ ZVAL_UNDEF(rval); ++ return 1; ++ } ++ if (Z_ISREF_P(rval_ref)) { ++ ZVAL_COPY(rval, rval_ref); ++ } else { ++ ZVAL_NEW_REF(rval_ref, rval_ref); ++ ZVAL_COPY(rval, rval_ref); + } - *rval = *rval_ref; - Z_ADDREF_PP(rval); - Z_SET_ISREF_PP(rval); + + return 1; + } -#line 936 "ext/standard/var_unserializer.c" ++#line 989 "ext/standard/var_unserializer.c" + yy65: + yych = *++YYCURSOR; + if (yych == '"') goto yy84; + goto yy18; + yy66: + yych = *++YYCURSOR; + if (yych == '{') goto yy86; + goto yy18; + yy67: + ++YYCURSOR; -#line 588 "ext/standard/var_unserializer.re" ++#line 643 "ext/standard/var_unserializer.re" + { + *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_BOOL(*rval, parse_iv(start + 2)); ++ ZVAL_BOOL(rval, parse_iv(start + 2)); + return 1; + } -#line 954 "ext/standard/var_unserializer.c" ++#line 1006 "ext/standard/var_unserializer.c" + yy69: ++YYCURSOR; if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); yych = *YYCURSOR; @@@ -1124,123 -968,44 +1020,43 @@@ goto yy18; } } - yy63: + yy71: ++YYCURSOR; - #line 668 "ext/standard/var_unserializer.re" -#line 637 "ext/standard/var_unserializer.re" ++#line 691 "ext/standard/var_unserializer.re" { -#if SIZEOF_LONG == 4 +#if SIZEOF_ZEND_LONG == 4 use_double: #endif *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_DOUBLE(*rval, zend_strtod((const char *)start + 2, NULL)); + ZVAL_DOUBLE(rval, zend_strtod((const char *)start + 2, NULL)); return 1; } - #line 1139 "ext/standard/var_unserializer.c" - yy65: -#line 984 "ext/standard/var_unserializer.c" ++#line 1035 "ext/standard/var_unserializer.c" + yy73: yych = *++YYCURSOR; if (yych <= ',') { - if (yych != '+') goto yy18; + if (yych == '+') goto yy88; + goto yy18; } else { - if (yych <= '-') goto yy66; + if (yych <= '-') goto yy88; if (yych <= '/') goto yy18; - if (yych <= '9') goto yy67; + if (yych <= '9') goto yy89; goto yy18; } - yy66: + yy74: yych = *++YYCURSOR; - if (yych <= ',') { - if (yych == '+') goto yy69; - goto yy18; - } else { - if (yych <= '-') goto yy69; - if (yych <= '/') goto yy18; - if (yych >= ':') goto yy18; - } - yy67: - ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy67; - if (yych == ';') goto yy63; + if (yych == 'F') goto yy91; goto yy18; - yy69: + yy75: yych = *++YYCURSOR; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy67; + if (yych == 'N') goto yy91; goto yy18; - yy70: - ++YYCURSOR; - if ((YYLIMIT - YYCURSOR) < 4) YYFILL(4); - yych = *YYCURSOR; - if (yych <= ';') { - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy70; - if (yych <= ':') goto yy18; - goto yy63; - } else { - if (yych <= 'E') { - if (yych <= 'D') goto yy18; - goto yy65; - } else { - if (yych == 'e') goto yy65; - goto yy18; - } - } - yy72: - yych = *++YYCURSOR; - if (yych != 'F') goto yy18; - yy73: - yych = *++YYCURSOR; - if (yych != ';') goto yy18; + yy76: ++YYCURSOR; - #line 652 "ext/standard/var_unserializer.re" -#line 595 "ext/standard/var_unserializer.re" ++#line 649 "ext/standard/var_unserializer.re" { - *p = YYCURSOR; - - if (!strncmp((char*)start + 2, "NAN", 3)) { - ZVAL_DOUBLE(rval, php_get_nan()); - } else if (!strncmp((char*)start + 2, "INF", 3)) { - ZVAL_DOUBLE(rval, php_get_inf()); - } else if (!strncmp((char*)start + 2, "-INF", 4)) { - ZVAL_DOUBLE(rval, -php_get_inf()); - } else { - ZVAL_NULL(rval); - } - - return 1; - } - #line 1214 "ext/standard/var_unserializer.c" - yy76: - yych = *++YYCURSOR; - if (yych == 'N') goto yy73; - goto yy18; - yy77: - yych = *++YYCURSOR; - if (yych <= ',') { - if (yych != '+') goto yy18; - } else { - if (yych <= '-') goto yy78; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy79; - goto yy18; - } - yy78: - yych = *++YYCURSOR; - if (yych <= '/') goto yy18; - if (yych >= ':') goto yy18; - yy79: - ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy79; - if (yych != ';') goto yy18; - ++YYCURSOR; - #line 626 "ext/standard/var_unserializer.re" - { - #if SIZEOF_ZEND_LONG == 4 - int digits = YYCURSOR - start - 3; -#if SIZEOF_LONG == 4 ++#if SIZEOF_ZEND_LONG == 4 + int digits = YYCURSOR - start - 3; if (start[2] == '-' || start[2] == '+') { digits--; @@@ -1260,58 -1025,20 +1076,19 @@@ } #endif *p = YYCURSOR; - INIT_PZVAL(*rval); - ZVAL_LONG(*rval, parse_iv(start + 2)); + ZVAL_LONG(rval, parse_iv(start + 2)); return 1; } - #line 1267 "ext/standard/var_unserializer.c" - yy83: - yych = *++YYCURSOR; - if (yych <= '/') goto yy18; - if (yych >= '2') goto yy18; - yych = *++YYCURSOR; - if (yych != ';') goto yy18; - ++YYCURSOR; - #line 620 "ext/standard/var_unserializer.re" - { - *p = YYCURSOR; - ZVAL_BOOL(rval, parse_iv(start + 2)); - return 1; - } - #line 1281 "ext/standard/var_unserializer.c" - yy87: - ++YYCURSOR; - #line 614 "ext/standard/var_unserializer.re" - { - *p = YYCURSOR; - ZVAL_NULL(rval); - return 1; - } - #line 1290 "ext/standard/var_unserializer.c" - yy89: - yych = *++YYCURSOR; - if (yych <= ',') { - if (yych != '+') goto yy18; - } else { - if (yych <= '-') goto yy90; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy91; - goto yy18; - } - yy90: -#line 1033 "ext/standard/var_unserializer.c" ++#line 1083 "ext/standard/var_unserializer.c" + yy78: yych = *++YYCURSOR; - if (yych <= '/') goto yy18; - if (yych >= ':') goto yy18; - yy91: - ++YYCURSOR; - if (YYLIMIT <= YYCURSOR) YYFILL(1); - yych = *YYCURSOR; - if (yych <= '/') goto yy18; - if (yych <= '9') goto yy91; - if (yych != ';') goto yy18; + if (yych == '"') goto yy92; + goto yy18; + yy79: ++YYCURSOR; - #line 589 "ext/standard/var_unserializer.re" -#line 558 "ext/standard/var_unserializer.re" ++#line 612 "ext/standard/var_unserializer.re" { - long id; + zend_long id; *p = YYCURSOR; if (!var_hash) return 0; @@@ -1334,11 -1059,235 +1111,235 @@@ return 1; } -#line 1063 "ext/standard/var_unserializer.c" ++#line 1115 "ext/standard/var_unserializer.c" + yy81: + yych = *++YYCURSOR; + if (yych == '"') goto yy94; + goto yy18; + yy82: + ++YYCURSOR; -#line 749 "ext/standard/var_unserializer.re" ++#line 801 "ext/standard/var_unserializer.re" + { + size_t len, len2, len3, maxlen; - long elements; - char *class_name; ++ zend_long elements; ++ char *str; ++ zend_string *class_name; + zend_class_entry *ce; - zend_class_entry **pce; + int incomplete_class = 0; + + int custom_object = 0; + - zval *user_func; - zval *retval_ptr; - zval **args[1]; - zval *arg_func_name; ++ zval user_func; ++ zval retval; ++ zval args[1]; + + if (!var_hash) return 0; + if (*start == 'C') { + custom_object = 1; + } + - INIT_PZVAL(*rval); + len2 = len = parse_uiv(start + 2); + maxlen = max - YYCURSOR; + if (maxlen < len || len == 0) { + *p = start + 2; + return 0; + } + - class_name = (char*)YYCURSOR; ++ str = (char*)YYCURSOR; + + YYCURSOR += len; + + if (*(YYCURSOR) != '"') { + *p = YYCURSOR; + return 0; + } + if (*(YYCURSOR+1) != ':') { + *p = YYCURSOR+1; + return 0; + } + - len3 = strspn(class_name, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\"); ++ len3 = strspn(str, "0123456789_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\177\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377\\"); + if (len3 != len) + { + *p = YYCURSOR + len3 - len; + return 0; + } + - class_name = estrndup(class_name, len); ++ class_name = zend_string_init(str, len, 0); + + do { ++ if(!unserialize_allowed_class(class_name, classes)) { ++ incomplete_class = 1; ++ ce = PHP_IC_ENTRY; ++ break; ++ } ++ + /* Try to find class directly */ + BG(serialize_lock)++; - if (zend_lookup_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) { ++ ce = zend_lookup_class(class_name); ++ if (ce) { + BG(serialize_lock)--; + if (EG(exception)) { - efree(class_name); ++ zend_string_release(class_name); + return 0; + } - ce = *pce; + break; + } + BG(serialize_lock)--; + + if (EG(exception)) { - efree(class_name); ++ zend_string_release(class_name); + return 0; + } + + /* Check for unserialize callback */ + if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) { + incomplete_class = 1; + ce = PHP_IC_ENTRY; + break; + } + + /* Call unserialize callback */ - MAKE_STD_ZVAL(user_func); - ZVAL_STRING(user_func, PG(unserialize_callback_func), 1); - args[0] = &arg_func_name; - MAKE_STD_ZVAL(arg_func_name); - ZVAL_STRING(arg_func_name, class_name, 1); ++ ZVAL_STRING(&user_func, PG(unserialize_callback_func)); ++ ++ ZVAL_STR_COPY(&args[0], class_name); + BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) { ++ if (call_user_function_ex(CG(function_table), NULL, &user_func, &retval, 1, args, 0, NULL) != SUCCESS) { + BG(serialize_lock)--; + if (EG(exception)) { - efree(class_name); ++ zend_string_release(class_name); + zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); ++ zval_ptr_dtor(&args[0]); + return 0; + } - php_error_docref(NULL TSRMLS_CC, E_WARNING, "defined (%s) but not found", user_func->value.str.val); ++ php_error_docref(NULL, E_WARNING, "defined (%s) but not found", Z_STRVAL(user_func)); + incomplete_class = 1; + ce = PHP_IC_ENTRY; + zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); ++ zval_ptr_dtor(&args[0]); + break; + } + BG(serialize_lock)--; - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } ++ zval_ptr_dtor(&retval); + if (EG(exception)) { - efree(class_name); ++ zend_string_release(class_name); + zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); ++ zval_ptr_dtor(&args[0]); + return 0; + } + + /* The callback function may have defined the class */ + BG(serialize_lock)++; - if (zend_lookup_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) { - ce = *pce; - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function %s() hasn't defined the class it was called for", user_func->value.str.val); ++ if ((ce = zend_lookup_class(class_name)) == NULL) { ++ php_error_docref(NULL, E_WARNING, "Function %s() hasn't defined the class it was called for", Z_STRVAL(user_func)); + incomplete_class = 1; + ce = PHP_IC_ENTRY; + } + BG(serialize_lock)--; + + zval_ptr_dtor(&user_func); - zval_ptr_dtor(&arg_func_name); ++ zval_ptr_dtor(&args[0]); + break; + } while (1); + + *p = YYCURSOR; + + if (custom_object) { + int ret; + + ret = object_custom(UNSERIALIZE_PASSTHRU, ce); + + if (ret && incomplete_class) { - php_store_class_name(*rval, class_name, len2); ++ php_store_class_name(rval, ZSTR_VAL(class_name), len2); + } - efree(class_name); ++ zend_string_release(class_name); + return ret; + } + + elements = object_common1(UNSERIALIZE_PASSTHRU, ce); + + if (elements < 0) { - efree(class_name); ++ zend_string_release(class_name); + return 0; + } + + if (incomplete_class) { - php_store_class_name(*rval, class_name, len2); ++ php_store_class_name(rval, ZSTR_VAL(class_name), len2); + } - efree(class_name); ++ zend_string_release(class_name); + + return object_common2(UNSERIALIZE_PASSTHRU, elements); + } -#line 1224 "ext/standard/var_unserializer.c" ++#line 1274 "ext/standard/var_unserializer.c" + yy84: + ++YYCURSOR; -#line 680 "ext/standard/var_unserializer.re" ++#line 732 "ext/standard/var_unserializer.re" + { + size_t len, maxlen; - char *str; ++ zend_string *str; + + len = parse_uiv(start + 2); + maxlen = max - YYCURSOR; + if (maxlen < len) { + *p = start + 2; + return 0; + } + - if ((str = unserialize_str(&YYCURSOR, &len, maxlen)) == NULL) { ++ if ((str = unserialize_str(&YYCURSOR, len, maxlen)) == NULL) { + return 0; + } + + if (*(YYCURSOR) != '"') { - efree(str); ++ zend_string_free(str); + *p = YYCURSOR; + return 0; + } + + if (*(YYCURSOR + 1) != ';') { + efree(str); + *p = YYCURSOR + 1; + return 0; + } + + YYCURSOR += 2; + *p = YYCURSOR; + - INIT_PZVAL(*rval); - ZVAL_STRINGL(*rval, str, len, 0); ++ ZVAL_STR(rval, str); + return 1; + } -#line 1262 "ext/standard/var_unserializer.c" ++#line 1311 "ext/standard/var_unserializer.c" + yy86: + ++YYCURSOR; -#line 715 "ext/standard/var_unserializer.re" ++#line 766 "ext/standard/var_unserializer.re" + { - long elements = parse_iv(start + 2); ++ zend_long elements = parse_iv(start + 2); + /* use iv() not uiv() in order to check data range */ + *p = YYCURSOR; + if (!var_hash) return 0; + + if (elements < 0) { + return 0; + } + - INIT_PZVAL(*rval); - - array_init_size(*rval, elements); ++ array_init_size(rval, elements); ++ if (elements) { ++ /* we can't convert from packed to hash during unserialization, because ++ reference to some zvals might be keept in var_hash (to support references) */ ++ zend_hash_real_init(Z_ARRVAL_P(rval), 0); ++ } + - if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_PP(rval), elements, 0)) { ++ if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_P(rval), elements, 0)) { + return 0; + } + + return finish_nested_data(UNSERIALIZE_PASSTHRU); + } -#line 1286 "ext/standard/var_unserializer.c" +#line 1338 "ext/standard/var_unserializer.c" - yy95: + yy88: yych = *++YYCURSOR; if (yych <= ',') { - if (yych != '+') goto yy18; + if (yych == '+') goto yy96; + goto yy18; } else { if (yych <= '-') goto yy96; if (yych <= '/') goto yy18; @@@ -1354,38 -1298,90 +1350,88 @@@ yy89 if (YYLIMIT <= YYCURSOR) YYFILL(1); yych = *YYCURSOR; if (yych <= '/') goto yy18; - if (yych <= '9') goto yy97; - if (yych != ';') goto yy18; + if (yych <= '9') goto yy89; + if (yych == ';') goto yy71; + goto yy18; + yy91: + yych = *++YYCURSOR; + if (yych == ';') goto yy97; + goto yy18; + yy92: ++YYCURSOR; - #line 563 "ext/standard/var_unserializer.re" -#line 736 "ext/standard/var_unserializer.re" ++#line 790 "ext/standard/var_unserializer.re" { - zend_long id; + long elements; + if (!var_hash) return 0; - *p = YYCURSOR; - if (!var_hash) return 0; - INIT_PZVAL(*rval); - + elements = object_common1(UNSERIALIZE_PASSTHRU, ZEND_STANDARD_CLASS_DEF_PTR); + if (elements < 0) { + return 0; + } + return object_common2(UNSERIALIZE_PASSTHRU, elements); + } -#line 1324 "ext/standard/var_unserializer.c" ++#line 1374 "ext/standard/var_unserializer.c" + yy94: + ++YYCURSOR; -#line 647 "ext/standard/var_unserializer.re" ++#line 700 "ext/standard/var_unserializer.re" + { + size_t len, maxlen; + char *str; - id = parse_iv(start + 2) - 1; - if (id == -1 || (rval_ref = var_access(var_hash, id)) == NULL) { + len = parse_uiv(start + 2); + maxlen = max - YYCURSOR; + if (maxlen < len) { + *p = start + 2; return 0; } - zval_ptr_dtor(rval); - if (Z_ISUNDEF_P(rval_ref) || (Z_ISREF_P(rval_ref) && Z_ISUNDEF_P(Z_REFVAL_P(rval_ref)))) { - ZVAL_UNDEF(rval); - return 1; + str = (char*)YYCURSOR; + + YYCURSOR += len; + + if (*(YYCURSOR) != '"') { + *p = YYCURSOR; + return 0; } - if (Z_ISREF_P(rval_ref)) { - ZVAL_COPY(rval, rval_ref); + + if (*(YYCURSOR + 1) != ';') { + *p = YYCURSOR + 1; + return 0; + } + + YYCURSOR += 2; + *p = YYCURSOR; + - INIT_PZVAL(*rval); - ZVAL_STRINGL(*rval, str, len, 1); ++ ZVAL_STRINGL(rval, str, len); + return 1; + } -#line 1360 "ext/standard/var_unserializer.c" ++#line 1409 "ext/standard/var_unserializer.c" + yy96: + yych = *++YYCURSOR; + if (yych <= '/') goto yy18; + if (yych <= '9') goto yy89; + goto yy18; + yy97: + ++YYCURSOR; -#line 622 "ext/standard/var_unserializer.re" ++#line 675 "ext/standard/var_unserializer.re" + { + *p = YYCURSOR; - INIT_PZVAL(*rval); + - if (!strncmp(start + 2, "NAN", 3)) { - ZVAL_DOUBLE(*rval, php_get_nan()); - } else if (!strncmp(start + 2, "INF", 3)) { - ZVAL_DOUBLE(*rval, php_get_inf()); - } else if (!strncmp(start + 2, "-INF", 4)) { - ZVAL_DOUBLE(*rval, -php_get_inf()); ++ if (!strncmp((char*)start + 2, "NAN", 3)) { ++ ZVAL_DOUBLE(rval, php_get_nan()); ++ } else if (!strncmp((char*)start + 2, "INF", 3)) { ++ ZVAL_DOUBLE(rval, php_get_inf()); ++ } else if (!strncmp((char*)start + 2, "-INF", 4)) { ++ ZVAL_DOUBLE(rval, -php_get_inf()); + } else { - ZVAL_NEW_REF(rval_ref, rval_ref); - ZVAL_COPY(rval, rval_ref); ++ ZVAL_NULL(rval); } return 1; } - #line 1387 "ext/standard/var_unserializer.c" -#line 1383 "ext/standard/var_unserializer.c" ++#line 1433 "ext/standard/var_unserializer.c" } - #line 938 "ext/standard/var_unserializer.re" -#line 911 "ext/standard/var_unserializer.re" ++#line 961 "ext/standard/var_unserializer.re" return 0; diff --cc ext/standard/var_unserializer.re index 9e6bb5d,bb0000b..b5f459a --- a/ext/standard/var_unserializer.re +++ b/ext/standard/var_unserializer.re @@@ -26,9 -26,14 +26,12 @@@ #define VAR_ENTRIES_MAX 1024 #define VAR_ENTRIES_DBG 0 ++/* VAR_FLAG used in var_dtor entries to signify an entry on which __wakeup should be called */ + #define VAR_WAKEUP_FLAG 1 -#define WITH_WAKEUP_FLAG(zv_ptr) ((zval *) ((zend_uintptr_t) zv_ptr | VAR_WAKEUP_FLAG)) -#define WITHOUT_WAKEUP_FLAG(zv_ptr) ((zval *) ((zend_uintptr_t) zv_ptr & ~VAR_WAKEUP_FLAG)) -#define HAS_WAKEUP_FLAG(zv_ptr) ((zend_uintptr_t) zv_ptr & VAR_WAKEUP_FLAG) + typedef struct { zval *data[VAR_ENTRIES_MAX]; - long used_slots; + zend_long used_slots; void *next; } var_entries; @@@ -80,29 -107,33 +83,30 @@@ PHPAPI zval *var_tmp_var(php_unserializ } var_hash = (*var_hashx)->last_dtor; -#if VAR_ENTRIES_DBG - fprintf(stderr, "var_push_dtor_no_addref(%p, %ld): %d (%d)\n", *rval, var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(rval), Z_REFCOUNT_PP(rval)); -#endif - - if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) { - var_hash = emalloc(sizeof(var_entries)); - var_hash->used_slots = 0; - var_hash->next = 0; - - if (!(*var_hashx)->first_dtor) { - (*var_hashx)->first_dtor = var_hash; - } else { - ((var_entries *) (*var_hashx)->last_dtor)->next = var_hash; - } - - (*var_hashx)->last_dtor = var_hash; - } - - var_hash->data[var_hash->used_slots++] = *rval; + if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) { + var_hash = emalloc(sizeof(var_dtor_entries)); + var_hash->used_slots = 0; + var_hash->next = 0; + + if (!(*var_hashx)->first_dtor) { + (*var_hashx)->first_dtor = var_hash; + } else { + ((var_dtor_entries *) (*var_hashx)->last_dtor)->next = var_hash; + } + + (*var_hashx)->last_dtor = var_hash; + } + ZVAL_UNDEF(&var_hash->data[var_hash->used_slots]); ++ Z_VAR_FLAGS(var_hash->data[var_hash->used_slots]) = 0; + return &var_hash->data[var_hash->used_slots++]; } -PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval) +PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval *nzval) { - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; #if VAR_ENTRIES_DBG - fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(nzval)); + fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_P(nzval)); #endif while (var_hash) { @@@ -138,9 -171,11 +142,13 @@@ static zval *var_access(php_unserialize PHPAPI void var_destroy(php_unserialize_data_t *var_hashx) { void *next; - long i; + zend_long i; var_entries *var_hash = (*var_hashx)->first; + var_dtor_entries *var_dtor_hash = (*var_hashx)->first_dtor; + zend_bool wakeup_failed = 0; - TSRMLS_FETCH(); ++ zval wakeup_name; ++ ZVAL_UNDEF(&wakeup_name); + #if VAR_ENTRIES_DBG fprintf(stderr, "var_destroy(%ld)\n", var_hash?var_hash->used_slots:-1L); #endif @@@ -151,17 -186,44 +159,42 @@@ var_hash = next; } - var_hash = (*var_hashx)->first_dtor; - - while (var_hash) { - for (i = 0; i < var_hash->used_slots; i++) { - zval *zv = var_hash->data[i]; + while (var_dtor_hash) { + for (i = 0; i < var_dtor_hash->used_slots; i++) { ++ zval *zv = &var_dtor_hash->data[i]; #if VAR_ENTRIES_DBG - fprintf(stderr, "var_destroy dtor(%p, %ld)\n", var_hash->data[i], Z_REFCOUNT_P(var_hash->data[i])); + fprintf(stderr, "var_destroy dtor(%p, %ld)\n", var_dtor_hash->data[i], Z_REFCOUNT_P(var_dtor_hash->data[i])); #endif - zval_ptr_dtor(&var_dtor_hash->data[i]); + - if (HAS_WAKEUP_FLAG(zv)) { - zv = WITHOUT_WAKEUP_FLAG(zv); ++ /* Perform delayed __wakeup calls */ ++ if (Z_VAR_FLAGS_P(zv) == VAR_WAKEUP_FLAG) { + if (!wakeup_failed) { - zval *retval_ptr = NULL; - zval wakeup_name; - INIT_PZVAL(&wakeup_name); - ZVAL_STRINGL(&wakeup_name, "__wakeup", sizeof("__wakeup") - 1, 0); ++ zval retval; ++ if (Z_ISUNDEF(wakeup_name)) { ++ ZVAL_STRINGL(&wakeup_name, "__wakeup", sizeof("__wakeup") - 1); ++ } + + BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), &zv, &wakeup_name, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC) == FAILURE || retval_ptr == NULL) { ++ if (call_user_function_ex(CG(function_table), zv, &wakeup_name, &retval, 0, 0, 1, NULL) == FAILURE || Z_ISUNDEF(retval)) { + wakeup_failed = 1; - zend_object_store_ctor_failed(zv TSRMLS_CC); ++ GC_FLAGS(Z_OBJ_P(zv)) |= IS_OBJ_DESTRUCTOR_CALLED; + } + BG(serialize_lock)--; + - if (retval_ptr) { - zval_ptr_dtor(&retval_ptr); - } ++ zval_ptr_dtor(&retval); + } else { - zend_object_store_ctor_failed(zv TSRMLS_CC); ++ GC_FLAGS(Z_OBJ_P(zv)) |= IS_OBJ_DESTRUCTOR_CALLED; + } + } + - zval_ptr_dtor(&zv); ++ zval_ptr_dtor(zv); } - next = var_hash->next; - efree(var_hash); - var_hash = next; + next = var_dtor_hash->next; + efree_size(var_dtor_hash, sizeof(var_dtor_entries)); + var_dtor_hash = next; } ++ ++ zval_ptr_dtor(&wakeup_name); } /* }}} */ @@@ -461,14 -472,9 +494,12 @@@ static inline zend_long object_common1( #ifdef PHP_WIN32 # pragma optimize("", off) #endif -static inline int object_common2(UNSERIALIZE_PARAMETER, long elements) +static inline int object_common2(UNSERIALIZE_PARAMETER, zend_long elements) { - zval retval; - zval fname; - if (Z_TYPE_PP(rval) != IS_OBJECT) { + HashTable *ht; + zend_bool has_wakeup; + + if (Z_TYPE_P(rval) != IS_OBJECT) { return 0; } @@@ -485,20 -487,22 +516,12 @@@ return 0; } - if (Z_TYPE_PP(rval) != IS_OBJECT) { - return 0; - } - - if (Z_OBJCE_PP(rval) != PHP_IC_ENTRY && - zend_hash_exists(&Z_OBJCE_PP(rval)->function_table, "__wakeup", sizeof("__wakeup")) - ) { - /* Store object for delayed __wakeup call. Remove references. */ - zval **slot = get_var_push_dtor_slot(var_hash); - zval *zv = *rval; - Z_ADDREF_P(zv); - if (PZVAL_IS_REF(zv)) { - SEPARATE_ZVAL(&zv); - } - *slot = WITH_WAKEUP_FLAG(zv); + ZVAL_DEREF(rval); + if (has_wakeup) { - ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1); - BG(serialize_lock)++; - if (call_user_function_ex(CG(function_table), rval, &fname, &retval, 0, 0, 1, NULL) == FAILURE || Z_ISUNDEF(retval)) { - GC_FLAGS(Z_OBJ_P(rval)) |= IS_OBJ_DESTRUCTOR_CALLED; - } - BG(serialize_lock)--; - zval_dtor(&fname); - zval_dtor(&retval); - } - - if (EG(exception)) { - return 0; ++ /* Delay __wakeup call until end of serialization */ ++ zval *wakeup_var = var_tmp_var(var_hash); ++ ZVAL_COPY(wakeup_var, rval); ++ Z_VAR_FLAGS_P(wakeup_var) = VAR_WAKEUP_FLAG; } return finish_nested_data(UNSERIALIZE_PASSTHRU);