2 +----------------------------------------------------------------------+
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: Jani Lehtimäki <jkl@njet.net> |
16 +----------------------------------------------------------------------+
24 #include "ext/standard/basic_functions.h"
25 #include "ext/standard/php_smart_str_public.h"
27 PHP_FUNCTION(var_dump
);
28 PHP_FUNCTION(var_export
);
29 PHP_FUNCTION(debug_zval_dump
);
30 PHP_FUNCTION(serialize
);
31 PHP_FUNCTION(unserialize
);
32 PHP_FUNCTION(memory_get_usage
);
33 PHP_FUNCTION(memory_get_peak_usage
);
35 PHPAPI
void php_var_dump(zval
**struc
, int level TSRMLS_DC
);
36 PHPAPI
void php_var_export(zval
**struc
, int level TSRMLS_DC
);
37 PHPAPI
void php_var_export_ex(zval
**struc
, int level
, smart_str
*buf TSRMLS_DC
);
39 PHPAPI
void php_debug_zval_dump(zval
**struc
, int level TSRMLS_DC
);
41 typedef HashTable
* php_serialize_data_t
;
43 struct php_unserialize_data
{
50 typedef struct php_unserialize_data
* php_unserialize_data_t
;
52 PHPAPI
void php_var_serialize(smart_str
*buf
, zval
**struc
, php_serialize_data_t
*var_hash TSRMLS_DC
);
53 PHPAPI
int php_var_unserialize(zval
**rval
, const unsigned char **p
, const unsigned char *max
, php_unserialize_data_t
*var_hash TSRMLS_DC
);
55 #define PHP_VAR_SERIALIZE_INIT(var_hash_ptr) \
57 /* fprintf(stderr, "SERIALIZE_INIT == lock: %u, level: %u\n", BG(serialize_lock), BG(serialize).level); */ \
58 if (BG(serialize_lock) || !BG(serialize).level) { \
59 ALLOC_HASHTABLE(var_hash_ptr); \
60 zend_hash_init((var_hash_ptr), 10, NULL, NULL, 0); \
61 if (!BG(serialize_lock)) { \
62 BG(serialize).var_hash = (void *)(var_hash_ptr); \
63 BG(serialize).level = 1; \
66 (var_hash_ptr) = (php_serialize_data_t)BG(serialize).var_hash; \
67 ++BG(serialize).level; \
71 #define PHP_VAR_SERIALIZE_DESTROY(var_hash_ptr) \
73 /* fprintf(stderr, "SERIALIZE_DESTROY == lock: %u, level: %u\n", BG(serialize_lock), BG(serialize).level); */ \
74 if (BG(serialize_lock) || !BG(serialize).level) { \
75 zend_hash_destroy((var_hash_ptr)); \
76 FREE_HASHTABLE(var_hash_ptr); \
78 if (!--BG(serialize).level) { \
79 zend_hash_destroy((php_serialize_data_t)BG(serialize).var_hash); \
80 FREE_HASHTABLE((php_serialize_data_t)BG(serialize).var_hash); \
81 BG(serialize).var_hash = NULL; \
86 #define PHP_VAR_UNSERIALIZE_INIT(var_hash_ptr) \
88 /* fprintf(stderr, "UNSERIALIZE_INIT == lock: %u, level: %u\n", BG(serialize_lock), BG(unserialize).level); */ \
89 if (BG(serialize_lock) || !BG(unserialize).level) { \
90 (var_hash_ptr) = (php_unserialize_data_t)ecalloc(1, sizeof(struct php_unserialize_data)); \
91 if (!BG(serialize_lock)) { \
92 BG(unserialize).var_hash = (void *)(var_hash_ptr); \
93 BG(unserialize).level = 1; \
96 (var_hash_ptr) = (php_unserialize_data_t)BG(unserialize).var_hash; \
97 ++BG(unserialize).level; \
101 #define PHP_VAR_UNSERIALIZE_DESTROY(var_hash_ptr) \
103 /* fprintf(stderr, "UNSERIALIZE_DESTROY == lock: %u, level: %u\n", BG(serialize_lock), BG(unserialize).level); */ \
104 if (BG(serialize_lock) || !BG(unserialize).level) { \
105 var_destroy(&(var_hash_ptr)); \
106 efree(var_hash_ptr); \
108 if (!--BG(unserialize).level) { \
109 var_destroy(&(var_hash_ptr)); \
110 efree((var_hash_ptr)); \
111 BG(unserialize).var_hash = NULL; \
116 PHPAPI
void var_replace(php_unserialize_data_t
*var_hash
, zval
*ozval
, zval
**nzval
);
117 PHPAPI
void var_push_dtor(php_unserialize_data_t
*var_hash
, zval
**val
);
118 PHPAPI
void var_destroy(php_unserialize_data_t
*var_hash
);
120 #define PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash, ozval, nzval) \
121 var_replace((var_hash), (ozval), &(nzval))
123 PHPAPI zend_class_entry
*php_create_empty_class(char *class_name
, int len
);
125 static inline int php_varname_check(char *name
, int name_len
, zend_bool silent TSRMLS_DC
) /* {{{ */
127 if (name_len
== sizeof("GLOBALS") - 1 && !memcmp(name
, "GLOBALS", sizeof("GLOBALS") - 1)) {
129 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Attempted GLOBALS variable overwrite");
132 } else if (name
[0] == '_' &&
134 (name_len
== sizeof("_GET") - 1 && !memcmp(name
, "_GET", sizeof("_GET") - 1)) ||
135 (name_len
== sizeof("_POST") - 1 && !memcmp(name
, "_POST", sizeof("_POST") - 1)) ||
136 (name_len
== sizeof("_COOKIE") - 1 && !memcmp(name
, "_COOKIE", sizeof("_COOKIE") - 1)) ||
137 (name_len
== sizeof("_ENV") - 1 && !memcmp(name
, "_ENV", sizeof("_ENV") - 1)) ||
138 (name_len
== sizeof("_SERVER") - 1 && !memcmp(name
, "_SERVER", sizeof("_SERVER") - 1)) ||
139 (name_len
== sizeof("_SESSION") - 1 && !memcmp(name
, "_SESSION", sizeof("_SESSION") - 1)) ||
140 (name_len
== sizeof("_FILES") - 1 && !memcmp(name
, "_FILES", sizeof("_FILES") - 1)) ||
141 (name_len
== sizeof("_REQUEST") -1 && !memcmp(name
, "_REQUEST", sizeof("_REQUEST") - 1))
145 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Attempted super-global (%s) variable overwrite", name
);
148 } else if (name
[0] == 'H' &&
150 (name_len
== sizeof("HTTP_POST_VARS") - 1 && !memcmp(name
, "HTTP_POST_VARS", sizeof("HTTP_POST_VARS") - 1)) ||
151 (name_len
== sizeof("HTTP_GET_VARS") - 1 && !memcmp(name
, "HTTP_GET_VARS", sizeof("HTTP_GET_VARS") - 1)) ||
152 (name_len
== sizeof("HTTP_COOKIE_VARS") - 1 && !memcmp(name
, "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS") - 1)) ||
153 (name_len
== sizeof("HTTP_ENV_VARS") - 1 && !memcmp(name
, "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS") - 1)) ||
154 (name_len
== sizeof("HTTP_SERVER_VARS") - 1 && !memcmp(name
, "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS") - 1)) ||
155 (name_len
== sizeof("HTTP_SESSION_VARS") - 1 && !memcmp(name
, "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS") - 1)) ||
156 (name_len
== sizeof("HTTP_RAW_POST_DATA") - 1 && !memcmp(name
, "HTTP_RAW_POST_DATA", sizeof("HTTP_RAW_POST_DATA") - 1)) ||
157 (name_len
== sizeof("HTTP_POST_FILES") - 1 && !memcmp(name
, "HTTP_POST_FILES", sizeof("HTTP_POST_FILES") - 1))
161 php_error_docref(NULL TSRMLS_CC
, E_WARNING
, "Attempted long input array (%s) overwrite", name
);
169 #endif /* PHP_VAR_H */