1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 6 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 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 : +----------------------------------------------------------------------+
17 : */
18 :
19 : /* $Id: php_var.h 276986 2009-03-10 23:40:06Z helly $ */
20 :
21 : #ifndef PHP_VAR_H
22 : #define PHP_VAR_H
23 :
24 : #include "ext/standard/php_smart_str_public.h"
25 :
26 : PHP_FUNCTION(var_dump);
27 : PHP_FUNCTION(var_inspect);
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);
34 :
35 : PHPAPI void php_var_dump(zval **struc, int level, int verbose TSRMLS_DC);
36 : PHPAPI void php_var_export(zval **struc, int level TSRMLS_DC);
37 : PHPAPI void php_debug_zval_dump(zval **struc, int level, int verbose TSRMLS_DC);
38 :
39 : /* typdef HashTable php_serialize_data_t; */
40 : #define php_serialize_data_t HashTable
41 :
42 : struct php_unserialize_data {
43 : void *first;
44 : void *first_dtor;
45 : };
46 :
47 : typedef struct php_unserialize_data php_unserialize_data_t;
48 :
49 : PHPAPI void php_var_serialize(smart_str *buf, zval **struc, php_serialize_data_t *var_hash TSRMLS_DC);
50 : PHPAPI int php_var_unserialize(zval **rval, const unsigned char **p, const unsigned char *max, php_unserialize_data_t *var_hash TSRMLS_DC);
51 :
52 : #define PHP_VAR_SERIALIZE_INIT(var_hash) \
53 : zend_hash_init(&(var_hash), 10, NULL, NULL, 0)
54 : #define PHP_VAR_SERIALIZE_DESTROY(var_hash) \
55 : zend_hash_destroy(&(var_hash))
56 :
57 : #define PHP_VAR_UNSERIALIZE_INIT(var_hash) \
58 : (var_hash).first = 0; \
59 : (var_hash).first_dtor = 0
60 : #define PHP_VAR_UNSERIALIZE_DESTROY(var_hash) \
61 : var_destroy(&(var_hash))
62 :
63 : PHPAPI void var_replace(php_unserialize_data_t *var_hash, zval *ozval, zval **nzval);
64 : PHPAPI void var_destroy(php_unserialize_data_t *var_hash);
65 :
66 : #define PHP_VAR_UNSERIALIZE_ZVAL_CHANGED(var_hash, ozval, nzval) \
67 : var_replace((var_hash), (ozval), &(nzval))
68 :
69 : PHPAPI zend_class_entry *php_create_empty_class(char *class_name, int len);
70 :
71 : static inline int php_varname_check_string(char * name, int name_len, zend_bool silent TSRMLS_DC) /* {{{ */
72 0 : {
73 0 : if (name_len == sizeof("GLOBALS")-1 && !memcmp(name, "GLOBALS", sizeof("GLOBALS")-1)) {
74 0 : if (!silent) {
75 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted GLOBALS variable overwrite");
76 : }
77 0 : return FAILURE;
78 0 : } else if (name[0] == '_' &&
79 : (
80 : (name_len == sizeof("_GET")-1 && !memcmp(name, "_GET", sizeof("_GET"))) ||
81 : (name_len == sizeof("_POST")-1 && !memcmp(name, "_POST", sizeof("_POST"))) ||
82 : (name_len == sizeof("_COOKIE")-1 && !memcmp(name, "_COOKIE", sizeof("_COOKIE"))) ||
83 : (name_len == sizeof("_ENV")-1 && !memcmp(name, "_ENV", sizeof("_ENV"))) ||
84 : (name_len == sizeof("_SERVER")-1 && !memcmp(name, "_SERVER", sizeof("_SERVER"))) ||
85 : (name_len == sizeof("_SESSION")-1 && !memcmp(name, "_SESSION", sizeof("_SESSION"))) ||
86 : (name_len == sizeof("_FILES")-1 && !memcmp(name, "_FILES", sizeof("_FILES"))) ||
87 : (name_len == sizeof("_REQUEST")-1 && !memcmp(name, "_REQUEST", sizeof("_REQUEST")))
88 : )
89 : ) {
90 0 : if (!silent) {
91 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted super-global (%s) variable overwrite", name);
92 : }
93 0 : return FAILURE;
94 0 : } else if (name[0] == 'H' &&
95 : (
96 : (name_len == sizeof("HTTP_POST_VARS")-1 && !memcmp(name, "HTTP_POST_VARS", sizeof("HTTP_POST_VARS"))) ||
97 : (name_len == sizeof("HTTP_GET_VARS")-1 && !memcmp(name, "HTTP_GET_VARS", sizeof("HTTP_GET_VARS"))) ||
98 : (name_len == sizeof("HTTP_COOKIE_VARS")-1 && !memcmp(name, "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS"))) ||
99 : (name_len == sizeof("HTTP_ENV_VARS")-1 && !memcmp(name, "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS"))) ||
100 : (name_len == sizeof("HTTP_SESSION_VARS")-1 && !memcmp(name, "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS"))) ||
101 : (name_len == sizeof("HTTP_SERVER_VARS")-1 && !memcmp(name, "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS"))) ||
102 : (name_len == sizeof("HTTP_RAW_POST_DATA")-1 && !memcmp(name, "HTTP_RAW_POST_DATA", sizeof("HTTP_RAW_POST_DATA"))) ||
103 : (name_len == sizeof("HTTP_POST_VARS")-1 && !memcmp(name, "HTTP_POST_FILES", sizeof("HTTP_POST_FILES")))
104 : )
105 : ) {
106 0 : if (!silent) {
107 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted long input array (%s) overwrite", name);
108 : }
109 0 : return FAILURE;
110 : }
111 0 : return SUCCESS;
112 : }
113 : /* }}} */
114 :
115 : static inline int php_varname_check_unicode(UChar *name, int name_len, zend_bool silent TSRMLS_DC) /* {{{ */
116 15 : {
117 15 : if (name_len == sizeof("GLOBALS")-1 && !zend_cmp_unicode_and_literal(name, name_len, "GLOBALS", sizeof("GLOBALS")-1)) {
118 0 : if (!silent) {
119 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted GLOBALS variable overwrite");
120 : }
121 0 : return FAILURE;
122 15 : } else if (name[0] == 0x5f /* '_' */ &&
123 : (
124 : (name_len == sizeof("_GET")-1 && !zend_cmp_unicode_and_literal(name, name_len, "_GET", sizeof("_GET")-1)) ||
125 : (name_len == sizeof("_POST")-1 && !zend_cmp_unicode_and_literal(name, name_len, "_POST", sizeof("_POST")-1)) ||
126 : (name_len == sizeof("_COOKIE")-1 && !zend_cmp_unicode_and_literal(name, name_len, "_COOKIE", sizeof("_COOKIE")-1)) ||
127 : (name_len == sizeof("_ENV")-1 && !zend_cmp_unicode_and_literal(name, name_len, "_ENV", sizeof("_ENV")-1)) ||
128 : (name_len == sizeof("_SERVER")-1 && !zend_cmp_unicode_and_literal(name, name_len, "_SERVER", sizeof("_SERVER")-1)) ||
129 : (name_len == sizeof("_SESSION")-1 && !zend_cmp_unicode_and_literal(name, name_len, "_SESSION", sizeof("_SESSION")-1)) ||
130 : (name_len == sizeof("_FILES")-1 && !zend_cmp_unicode_and_literal(name, name_len, "_FILES", sizeof("_FILES")-1)) ||
131 : (name_len == sizeof("_REQUEST")-1 && !zend_cmp_unicode_and_literal(name, name_len, "_REQUEST", sizeof("_REQUEST")-1))
132 : )
133 : ) {
134 5 : if (!silent) {
135 5 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted super-global (%r) variable overwrite", name);
136 : }
137 5 : return FAILURE;
138 10 : } else if (name[0] == 0x48 /* 'H' */ &&
139 : (
140 : (name_len == sizeof("HTTP_POST_VARS")-1 && !zend_cmp_unicode_and_literal(name, name_len, "HTTP_POST_VARS", sizeof("HTTP_POST_VARS")-1)) ||
141 : (name_len == sizeof("HTTP_GET_VARS")-1 && !zend_cmp_unicode_and_literal(name, name_len, "HTTP_GET_VARS", sizeof("HTTP_GET_VARS")-1)) ||
142 : (name_len == sizeof("HTTP_COOKIE_VARS")-1 && !zend_cmp_unicode_and_literal(name, name_len, "HTTP_COOKIE_VARS", sizeof("HTTP_COOKIE_VARS")-1)) ||
143 : (name_len == sizeof("HTTP_ENV_VARS")-1 && !zend_cmp_unicode_and_literal(name, name_len, "HTTP_ENV_VARS", sizeof("HTTP_ENV_VARS")-1)) ||
144 : (name_len == sizeof("HTTP_SESSION_VARS")-1 && !zend_cmp_unicode_and_literal(name, name_len, "HTTP_SESSION_VARS", sizeof("HTTP_SESSION_VARS")-1)) ||
145 : (name_len == sizeof("HTTP_SERVER_VARS")-1 && !zend_cmp_unicode_and_literal(name, name_len, "HTTP_SERVER_VARS", sizeof("HTTP_SERVER_VARS")-1)) ||
146 : (name_len == sizeof("HTTP_RAW_POST_DATA")-1 && !zend_cmp_unicode_and_literal(name, name_len, "HTTP_RAW_POST_DATA", sizeof("HTTP_RAW_POST_DATA")-1)) ||
147 : (name_len == sizeof("HTTP_POST_FILES")-1 && !zend_cmp_unicode_and_literal(name, name_len, "HTTP_POST_FILES", sizeof("HTTP_POST_FILES")-1))
148 : )
149 : ) {
150 0 : if (!silent) {
151 0 : php_error_docref(NULL TSRMLS_CC, E_WARNING, "Attempted long input array (%r) overwrite", name);
152 : }
153 0 : return FAILURE;
154 : }
155 10 : return SUCCESS;
156 : }
157 : /* }}} */
158 :
159 : static inline int php_varname_check(zend_uchar type, zstr name, int name_len, zend_bool silent TSRMLS_DC) /* {{{ */
160 15 : {
161 15 : if (type == IS_UNICODE) {
162 15 : return php_varname_check_unicode(name.u, name_len, silent TSRMLS_CC);
163 : }
164 0 : return php_varname_check_string(name.s, name_len, silent TSRMLS_CC);
165 : }
166 : /* }}} */
167 :
168 : #endif /* PHP_VAR_H */
|