1/*
2  +----------------------------------------------------------------------+
3  | PHP Version 5                                                        |
4  +----------------------------------------------------------------------+
5  | Copyright (c) 1997-2013 The PHP Group                                |
6  +----------------------------------------------------------------------+
7  | This source file is subject to version 3.01 of the PHP license,      |
8  | that is bundled with this package in the file LICENSE, and is        |
9  | available through the world-wide-web at the following url:           |
10  | http://www.php.net/license/3_01.txt                                  |
11  | If you did not receive a copy of the PHP license and are unable to   |
12  | obtain it through the world-wide-web, please send a note to          |
13  | license@php.net so we can mail you a copy immediately.               |
14  +----------------------------------------------------------------------+
15  | Author: Sascha Schumann <sascha@schumann.cx>                         |
16  +----------------------------------------------------------------------+
17*/
18
19/* $Id$ */
20
21#include "php.h"
22#include "ext/standard/php_var.h"
23#include "php_incomplete_class.h"
24
25/* {{{ reference-handling for unserializer: var_* */
26#define VAR_ENTRIES_MAX 1024
27#define VAR_ENTRIES_DBG 0
28
29typedef struct {
30    zval *data[VAR_ENTRIES_MAX];
31    long used_slots;
32    void *next;
33} var_entries;
34
35static inline void var_push(php_unserialize_data_t *var_hashx, zval **rval)
36{
37    var_entries *var_hash = (*var_hashx)->last;
38#if VAR_ENTRIES_DBG
39    fprintf(stderr, "var_push(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(rval));
40#endif
41
42    if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) {
43        var_hash = emalloc(sizeof(var_entries));
44        var_hash->used_slots = 0;
45        var_hash->next = 0;
46
47        if (!(*var_hashx)->first) {
48            (*var_hashx)->first = var_hash;
49        } else {
50            ((var_entries *) (*var_hashx)->last)->next = var_hash;
51        }
52
53        (*var_hashx)->last = var_hash;
54    }
55
56    var_hash->data[var_hash->used_slots++] = *rval;
57}
58
59PHPAPI void var_push_dtor(php_unserialize_data_t *var_hashx, zval **rval)
60{
61    var_entries *var_hash = (*var_hashx)->last_dtor;
62#if VAR_ENTRIES_DBG
63    fprintf(stderr, "var_push_dtor(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(rval));
64#endif
65
66    if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) {
67        var_hash = emalloc(sizeof(var_entries));
68        var_hash->used_slots = 0;
69        var_hash->next = 0;
70
71        if (!(*var_hashx)->first_dtor) {
72            (*var_hashx)->first_dtor = var_hash;
73        } else {
74            ((var_entries *) (*var_hashx)->last_dtor)->next = var_hash;
75        }
76
77        (*var_hashx)->last_dtor = var_hash;
78    }
79
80    Z_ADDREF_PP(rval);
81    var_hash->data[var_hash->used_slots++] = *rval;
82}
83
84PHPAPI void var_push_dtor_no_addref(php_unserialize_data_t *var_hashx, zval **rval)
85{
86    var_entries *var_hash = (*var_hashx)->last_dtor;
87#if VAR_ENTRIES_DBG
88    fprintf(stderr, "var_push_dtor_no_addref(%ld): %d (%d)\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(rval), Z_REFCOUNT_PP(rval));
89#endif
90
91    if (!var_hash || var_hash->used_slots == VAR_ENTRIES_MAX) {
92        var_hash = emalloc(sizeof(var_entries));
93        var_hash->used_slots = 0;
94        var_hash->next = 0;
95
96        if (!(*var_hashx)->first_dtor) {
97            (*var_hashx)->first_dtor = var_hash;
98        } else {
99            ((var_entries *) (*var_hashx)->last_dtor)->next = var_hash;
100        }
101
102        (*var_hashx)->last_dtor = var_hash;
103    }
104
105    var_hash->data[var_hash->used_slots++] = *rval;
106}
107
108PHPAPI void var_replace(php_unserialize_data_t *var_hashx, zval *ozval, zval **nzval)
109{
110    long i;
111    var_entries *var_hash = (*var_hashx)->first;
112#if VAR_ENTRIES_DBG
113    fprintf(stderr, "var_replace(%ld): %d\n", var_hash?var_hash->used_slots:-1L, Z_TYPE_PP(nzval));
114#endif
115
116    while (var_hash) {
117        for (i = 0; i < var_hash->used_slots; i++) {
118            if (var_hash->data[i] == ozval) {
119                var_hash->data[i] = *nzval;
120                /* do not break here */
121            }
122        }
123        var_hash = var_hash->next;
124    }
125}
126
127static int var_access(php_unserialize_data_t *var_hashx, long id, zval ***store)
128{
129    var_entries *var_hash = (*var_hashx)->first;
130#if VAR_ENTRIES_DBG
131    fprintf(stderr, "var_access(%ld): %ld\n", var_hash?var_hash->used_slots:-1L, id);
132#endif
133
134    while (id >= VAR_ENTRIES_MAX && var_hash && var_hash->used_slots == VAR_ENTRIES_MAX) {
135        var_hash = var_hash->next;
136        id -= VAR_ENTRIES_MAX;
137    }
138
139    if (!var_hash) return !SUCCESS;
140
141    if (id < 0 || id >= var_hash->used_slots) return !SUCCESS;
142
143    *store = &var_hash->data[id];
144
145    return SUCCESS;
146}
147
148PHPAPI void var_destroy(php_unserialize_data_t *var_hashx)
149{
150    void *next;
151    long i;
152    var_entries *var_hash = (*var_hashx)->first;
153#if VAR_ENTRIES_DBG
154    fprintf(stderr, "var_destroy(%ld)\n", var_hash?var_hash->used_slots:-1L);
155#endif
156
157    while (var_hash) {
158        next = var_hash->next;
159        efree(var_hash);
160        var_hash = next;
161    }
162
163    var_hash = (*var_hashx)->first_dtor;
164
165    while (var_hash) {
166        for (i = 0; i < var_hash->used_slots; i++) {
167            zval_ptr_dtor(&var_hash->data[i]);
168        }
169        next = var_hash->next;
170        efree(var_hash);
171        var_hash = next;
172    }
173}
174
175/* }}} */
176
177static char *unserialize_str(const unsigned char **p, size_t *len, size_t maxlen)
178{
179    size_t i, j;
180    char *str = safe_emalloc(*len, 1, 1);
181    unsigned char *end = *(unsigned char **)p+maxlen;
182
183    if (end < *p) {
184        efree(str);
185        return NULL;
186    }
187
188    for (i = 0; i < *len; i++) {
189        if (*p >= end) {
190            efree(str);
191            return NULL;
192        }
193        if (**p != '\\') {
194            str[i] = (char)**p;
195        } else {
196            unsigned char ch = 0;
197
198            for (j = 0; j < 2; j++) {
199                (*p)++;
200                if (**p >= '0' && **p <= '9') {
201                    ch = (ch << 4) + (**p -'0');
202                } else if (**p >= 'a' && **p <= 'f') {
203                    ch = (ch << 4) + (**p -'a'+10);
204                } else if (**p >= 'A' && **p <= 'F') {
205                    ch = (ch << 4) + (**p -'A'+10);
206                } else {
207                    efree(str);
208                    return NULL;
209                }
210            }
211            str[i] = (char)ch;
212        }
213        (*p)++;
214    }
215    str[i] = 0;
216    *len = i;
217    return str;
218}
219
220#define YYFILL(n) do { } while (0)
221#define YYCTYPE unsigned char
222#define YYCURSOR cursor
223#define YYLIMIT limit
224#define YYMARKER marker
225
226
227/*!re2c
228uiv = [+]? [0-9]+;
229iv = [+-]? [0-9]+;
230nv = [+-]? ([0-9]* "." [0-9]+|[0-9]+ "." [0-9]*);
231nvexp = (iv | nv) [eE] [+-]? iv;
232any = [\000-\377];
233object = [OC];
234*/
235
236
237
238static inline long parse_iv2(const unsigned char *p, const unsigned char **q)
239{
240    char cursor;
241    long result = 0;
242    int neg = 0;
243
244    switch (*p) {
245        case '-':
246            neg++;
247            /* fall-through */
248        case '+':
249            p++;
250    }
251
252    while (1) {
253        cursor = (char)*p;
254        if (cursor >= '0' && cursor <= '9') {
255            result = result * 10 + (size_t)(cursor - (unsigned char)'0');
256        } else {
257            break;
258        }
259        p++;
260    }
261    if (q) *q = p;
262    if (neg) return -result;
263    return result;
264}
265
266static inline long parse_iv(const unsigned char *p)
267{
268    return parse_iv2(p, NULL);
269}
270
271/* no need to check for length - re2c already did */
272static inline size_t parse_uiv(const unsigned char *p)
273{
274    unsigned char cursor;
275    size_t result = 0;
276
277    if (*p == '+') {
278        p++;
279    }
280
281    while (1) {
282        cursor = *p;
283        if (cursor >= '0' && cursor <= '9') {
284            result = result * 10 + (size_t)(cursor - (unsigned char)'0');
285        } else {
286            break;
287        }
288        p++;
289    }
290    return result;
291}
292
293#define UNSERIALIZE_PARAMETER zval **rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC
294#define UNSERIALIZE_PASSTHRU rval, p, max, var_hash TSRMLS_CC
295
296static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements, int objprops)
297{
298    while (elements-- > 0) {
299        zval *key, *data, **old_data;
300
301        ALLOC_INIT_ZVAL(key);
302
303        if (!php_var_unserialize(&key, p, max, NULL TSRMLS_CC)) {
304            zval_dtor(key);
305            FREE_ZVAL(key);
306            return 0;
307        }
308
309        if (Z_TYPE_P(key) != IS_LONG && Z_TYPE_P(key) != IS_STRING) {
310            zval_dtor(key);
311            FREE_ZVAL(key);
312            return 0;
313        }
314
315        ALLOC_INIT_ZVAL(data);
316
317        if (!php_var_unserialize(&data, p, max, var_hash TSRMLS_CC)) {
318            zval_dtor(key);
319            FREE_ZVAL(key);
320            zval_dtor(data);
321            FREE_ZVAL(data);
322            return 0;
323        }
324
325        if (!objprops) {
326            switch (Z_TYPE_P(key)) {
327            case IS_LONG:
328                if (zend_hash_index_find(ht, Z_LVAL_P(key), (void **)&old_data)==SUCCESS) {
329                    var_push_dtor(var_hash, old_data);
330                }
331                zend_hash_index_update(ht, Z_LVAL_P(key), &data, sizeof(data), NULL);
332                break;
333            case IS_STRING:
334                if (zend_symtable_find(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, (void **)&old_data)==SUCCESS) {
335                    var_push_dtor(var_hash, old_data);
336                }
337                zend_symtable_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data, sizeof(data), NULL);
338                break;
339            }
340        } else {
341            /* object properties should include no integers */
342            convert_to_string(key);
343            zend_hash_update(ht, Z_STRVAL_P(key), Z_STRLEN_P(key) + 1, &data,
344                    sizeof data, NULL);
345        }
346
347        zval_dtor(key);
348        FREE_ZVAL(key);
349
350        if (elements && *(*p-1) != ';' && *(*p-1) != '}') {
351            (*p)--;
352            return 0;
353        }
354    }
355
356    return 1;
357}
358
359static inline int finish_nested_data(UNSERIALIZE_PARAMETER)
360{
361    if (*((*p)++) == '}')
362        return 1;
363
364#if SOMETHING_NEW_MIGHT_LEAD_TO_CRASH_ENABLE_IF_YOU_ARE_BRAVE
365    zval_ptr_dtor(rval);
366#endif
367    return 0;
368}
369
370static inline int object_custom(UNSERIALIZE_PARAMETER, zend_class_entry *ce)
371{
372    long datalen;
373
374    datalen = parse_iv2((*p) + 2, p);
375
376    (*p) += 2;
377
378    if (datalen < 0 || (*p) + datalen >= max) {
379        zend_error(E_WARNING, "Insufficient data for unserializing - %ld required, %ld present", datalen, (long)(max - (*p)));
380        return 0;
381    }
382
383    if (ce->unserialize == NULL) {
384        zend_error(E_WARNING, "Class %s has no unserializer", ce->name);
385        object_init_ex(*rval, ce);
386    } else if (ce->unserialize(rval, ce, (const unsigned char*)*p, datalen, (zend_unserialize_data *)var_hash TSRMLS_CC) != SUCCESS) {
387        return 0;
388    }
389
390    (*p) += datalen;
391
392    return finish_nested_data(UNSERIALIZE_PASSTHRU);
393}
394
395static inline long object_common1(UNSERIALIZE_PARAMETER, zend_class_entry *ce)
396{
397    long elements;
398
399    elements = parse_iv2((*p) + 2, p);
400
401    (*p) += 2;
402
403    if (ce->unserialize == NULL) {
404        object_init_ex(*rval, ce);
405    } else if (ce->unserialize(rval, ce, (const unsigned char*)*p, elements, (zend_unserialize_data *)var_hash TSRMLS_CC) != SUCCESS) {
406        return 0;
407    }
408
409    return elements;
410}
411
412#ifdef PHP_WIN32
413# pragma optimize("", off)
414#endif
415static inline int object_common2(UNSERIALIZE_PARAMETER, long elements)
416{
417    zval *retval_ptr = NULL;
418    zval fname;
419
420    if (Z_TYPE_PP(rval) != IS_OBJECT) {
421        return 0;
422    }
423
424    if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_OBJPROP_PP(rval), elements, 1)) {
425        return 0;
426    }
427
428    if (Z_OBJCE_PP(rval) != PHP_IC_ENTRY &&
429        zend_hash_exists(&Z_OBJCE_PP(rval)->function_table, "__wakeup", sizeof("__wakeup"))) {
430        INIT_PZVAL(&fname);
431        ZVAL_STRINGL(&fname, "__wakeup", sizeof("__wakeup") - 1, 0);
432        BG(serialize_lock)++;
433        call_user_function_ex(CG(function_table), rval, &fname, &retval_ptr, 0, 0, 1, NULL TSRMLS_CC);
434        BG(serialize_lock)--;
435    }
436
437    if (retval_ptr) {
438        zval_ptr_dtor(&retval_ptr);
439    }
440
441    if (EG(exception)) {
442        return 0;
443    }
444
445    return finish_nested_data(UNSERIALIZE_PASSTHRU);
446
447}
448#ifdef PHP_WIN32
449# pragma optimize("", on)
450#endif
451
452PHPAPI int php_var_unserialize(UNSERIALIZE_PARAMETER)
453{
454    const unsigned char *cursor, *limit, *marker, *start;
455    zval **rval_ref;
456
457    limit = max;
458    cursor = *p;
459
460    if (YYCURSOR >= YYLIMIT) {
461        return 0;
462    }
463
464    if (var_hash && cursor[0] != 'R') {
465        var_push(var_hash, rval);
466    }
467
468    start = cursor;
469
470
471
472/*!re2c
473
474"R:" iv ";"     {
475    long id;
476
477    *p = YYCURSOR;
478    if (!var_hash) return 0;
479
480    id = parse_iv(start + 2) - 1;
481    if (id == -1 || var_access(var_hash, id, &rval_ref) != SUCCESS) {
482        return 0;
483    }
484
485    if (*rval != NULL) {
486        zval_ptr_dtor(rval);
487    }
488    *rval = *rval_ref;
489    Z_ADDREF_PP(rval);
490    Z_SET_ISREF_PP(rval);
491
492    return 1;
493}
494
495"r:" iv ";"     {
496    long id;
497
498    *p = YYCURSOR;
499    if (!var_hash) return 0;
500
501    id = parse_iv(start + 2) - 1;
502    if (id == -1 || var_access(var_hash, id, &rval_ref) != SUCCESS) {
503        return 0;
504    }
505
506    if (*rval == *rval_ref) return 0;
507
508    if (*rval != NULL) {
509        var_push_dtor_no_addref(var_hash, rval);
510    }
511    *rval = *rval_ref;
512    Z_ADDREF_PP(rval);
513    Z_UNSET_ISREF_PP(rval);
514
515    return 1;
516}
517
518"N;"    {
519    *p = YYCURSOR;
520    INIT_PZVAL(*rval);
521    ZVAL_NULL(*rval);
522    return 1;
523}
524
525"b:" [01] ";"   {
526    *p = YYCURSOR;
527    INIT_PZVAL(*rval);
528    ZVAL_BOOL(*rval, parse_iv(start + 2));
529    return 1;
530}
531
532"i:" iv ";" {
533#if SIZEOF_LONG == 4
534    int digits = YYCURSOR - start - 3;
535
536    if (start[2] == '-' || start[2] == '+') {
537        digits--;
538    }
539
540    /* Use double for large long values that were serialized on a 64-bit system */
541    if (digits >= MAX_LENGTH_OF_LONG - 1) {
542        if (digits == MAX_LENGTH_OF_LONG - 1) {
543            int cmp = strncmp(YYCURSOR - MAX_LENGTH_OF_LONG, long_min_digits, MAX_LENGTH_OF_LONG - 1);
544
545            if (!(cmp < 0 || (cmp == 0 && start[2] == '-'))) {
546                goto use_double;
547            }
548        } else {
549            goto use_double;
550        }
551    }
552#endif
553    *p = YYCURSOR;
554    INIT_PZVAL(*rval);
555    ZVAL_LONG(*rval, parse_iv(start + 2));
556    return 1;
557}
558
559"d:" ("NAN" | "-"? "INF") ";"   {
560    *p = YYCURSOR;
561    INIT_PZVAL(*rval);
562
563    if (!strncmp(start + 2, "NAN", 3)) {
564        ZVAL_DOUBLE(*rval, php_get_nan());
565    } else if (!strncmp(start + 2, "INF", 3)) {
566        ZVAL_DOUBLE(*rval, php_get_inf());
567    } else if (!strncmp(start + 2, "-INF", 4)) {
568        ZVAL_DOUBLE(*rval, -php_get_inf());
569    }
570
571    return 1;
572}
573
574"d:" (iv | nv | nvexp) ";"  {
575#if SIZEOF_LONG == 4
576use_double:
577#endif
578    *p = YYCURSOR;
579    INIT_PZVAL(*rval);
580    ZVAL_DOUBLE(*rval, zend_strtod((const char *)start + 2, NULL));
581    return 1;
582}
583
584"s:" uiv ":" ["]    {
585    size_t len, maxlen;
586    char *str;
587
588    len = parse_uiv(start + 2);
589    maxlen = max - YYCURSOR;
590    if (maxlen < len) {
591        *p = start + 2;
592        return 0;
593    }
594
595    str = (char*)YYCURSOR;
596
597    YYCURSOR += len;
598
599    if (*(YYCURSOR) != '"') {
600        *p = YYCURSOR;
601        return 0;
602    }
603
604    YYCURSOR += 2;
605    *p = YYCURSOR;
606
607    INIT_PZVAL(*rval);
608    ZVAL_STRINGL(*rval, str, len, 1);
609    return 1;
610}
611
612"S:" uiv ":" ["]    {
613    size_t len, maxlen;
614    char *str;
615
616    len = parse_uiv(start + 2);
617    maxlen = max - YYCURSOR;
618    if (maxlen < len) {
619        *p = start + 2;
620        return 0;
621    }
622
623    if ((str = unserialize_str(&YYCURSOR, &len, maxlen)) == NULL) {
624        return 0;
625    }
626
627    if (*(YYCURSOR) != '"') {
628        efree(str);
629        *p = YYCURSOR;
630        return 0;
631    }
632
633    YYCURSOR += 2;
634    *p = YYCURSOR;
635
636    INIT_PZVAL(*rval);
637    ZVAL_STRINGL(*rval, str, len, 0);
638    return 1;
639}
640
641"a:" uiv ":" "{" {
642    long elements = parse_iv(start + 2);
643    /* use iv() not uiv() in order to check data range */
644    *p = YYCURSOR;
645
646    if (elements < 0) {
647        return 0;
648    }
649
650    INIT_PZVAL(*rval);
651
652    array_init_size(*rval, elements);
653
654    if (!process_nested_data(UNSERIALIZE_PASSTHRU, Z_ARRVAL_PP(rval), elements, 0)) {
655        return 0;
656    }
657
658    return finish_nested_data(UNSERIALIZE_PASSTHRU);
659}
660
661"o:" iv ":" ["] {
662
663    INIT_PZVAL(*rval);
664
665    return object_common2(UNSERIALIZE_PASSTHRU,
666            object_common1(UNSERIALIZE_PASSTHRU, ZEND_STANDARD_CLASS_DEF_PTR));
667}
668
669object ":" uiv ":" ["]  {
670    size_t len, len2, len3, maxlen;
671    long elements;
672    char *class_name;
673    zend_class_entry *ce;
674    zend_class_entry **pce;
675    int incomplete_class = 0;
676
677    int custom_object = 0;
678
679    zval *user_func;
680    zval *retval_ptr;
681    zval **args[1];
682    zval *arg_func_name;
683
684    if (*start == 'C') {
685        custom_object = 1;
686    }
687
688    INIT_PZVAL(*rval);
689    len2 = len = parse_uiv(start + 2);
690    maxlen = max - YYCURSOR;
691    if (maxlen < len || len == 0) {
692        *p = start + 2;
693        return 0;
694    }
695
696    class_name = (char*)YYCURSOR;
697
698    YYCURSOR += len;
699
700    if (*(YYCURSOR) != '"') {
701        *p = YYCURSOR;
702        return 0;
703    }
704    if (*(YYCURSOR+1) != ':') {
705        *p = YYCURSOR+1;
706        return 0;
707    }
708
709    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\\");
710    if (len3 != len)
711    {
712        *p = YYCURSOR + len3 - len;
713        return 0;
714    }
715
716    class_name = estrndup(class_name, len);
717
718    do {
719        /* Try to find class directly */
720        BG(serialize_lock)++;
721        if (zend_lookup_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) {
722            BG(serialize_lock)--;
723            if (EG(exception)) {
724                efree(class_name);
725                return 0;
726            }
727            ce = *pce;
728            break;
729        }
730        BG(serialize_lock)--;
731
732        if (EG(exception)) {
733            efree(class_name);
734            return 0;
735        }
736
737        /* Check for unserialize callback */
738        if ((PG(unserialize_callback_func) == NULL) || (PG(unserialize_callback_func)[0] == '\0')) {
739            incomplete_class = 1;
740            ce = PHP_IC_ENTRY;
741            break;
742        }
743
744        /* Call unserialize callback */
745        MAKE_STD_ZVAL(user_func);
746        ZVAL_STRING(user_func, PG(unserialize_callback_func), 1);
747        args[0] = &arg_func_name;
748        MAKE_STD_ZVAL(arg_func_name);
749        ZVAL_STRING(arg_func_name, class_name, 1);
750        BG(serialize_lock)++;
751        if (call_user_function_ex(CG(function_table), NULL, user_func, &retval_ptr, 1, args, 0, NULL TSRMLS_CC) != SUCCESS) {
752            BG(serialize_lock)--;
753            if (EG(exception)) {
754                efree(class_name);
755                zval_ptr_dtor(&user_func);
756                zval_ptr_dtor(&arg_func_name);
757                return 0;
758            }
759            php_error_docref(NULL TSRMLS_CC, E_WARNING, "defined (%s) but not found", user_func->value.str.val);
760            incomplete_class = 1;
761            ce = PHP_IC_ENTRY;
762            zval_ptr_dtor(&user_func);
763            zval_ptr_dtor(&arg_func_name);
764            break;
765        }
766        BG(serialize_lock)--;
767        if (retval_ptr) {
768            zval_ptr_dtor(&retval_ptr);
769        }
770        if (EG(exception)) {
771            efree(class_name);
772            zval_ptr_dtor(&user_func);
773            zval_ptr_dtor(&arg_func_name);
774            return 0;
775        }
776
777        /* The callback function may have defined the class */
778        if (zend_lookup_class(class_name, len2, &pce TSRMLS_CC) == SUCCESS) {
779            ce = *pce;
780        } else {
781            php_error_docref(NULL TSRMLS_CC, E_WARNING, "Function %s() hasn't defined the class it was called for", user_func->value.str.val);
782            incomplete_class = 1;
783            ce = PHP_IC_ENTRY;
784        }
785
786        zval_ptr_dtor(&user_func);
787        zval_ptr_dtor(&arg_func_name);
788        break;
789    } while (1);
790
791    *p = YYCURSOR;
792
793    if (custom_object) {
794        int ret;
795
796        ret = object_custom(UNSERIALIZE_PASSTHRU, ce);
797
798        if (ret && incomplete_class) {
799            php_store_class_name(*rval, class_name, len2);
800        }
801        efree(class_name);
802        return ret;
803    }
804
805    elements = object_common1(UNSERIALIZE_PASSTHRU, ce);
806
807    if (incomplete_class) {
808        php_store_class_name(*rval, class_name, len2);
809    }
810    efree(class_name);
811
812    return object_common2(UNSERIALIZE_PASSTHRU, elements);
813}
814
815"}" {
816    /* this is the case where we have less data than planned */
817    php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unexpected end of serialized data");
818    return 0; /* not sure if it should be 0 or 1 here? */
819}
820
821any { return 0; }
822
823*/
824
825    return 0;
826}
827