Annotation of /trunk/php5/patches/php5-5.2.4-suhosin-0.9.6.2.patch
Parent Directory | Revision Log
Revision 343 -
(hide annotations)
(download)
Fri Sep 7 18:27:59 2007 UTC (17 years ago) by niro
File size: 93793 byte(s)
Fri Sep 7 18:27:59 2007 UTC (17 years ago) by niro
File size: 93793 byte(s)
-rediffed against php-5.2.4
1 | niro | 343 | diff -Naur php-5.2.4/configure php-5.2.4-suhosin/configure |
2 | --- php-5.2.4/configure 2007-08-30 01:39:18.000000000 +0200 | ||
3 | +++ php-5.2.4-suhosin/configure 2007-09-07 20:11:39.000000000 +0200 | ||
4 | @@ -18496,6 +18496,9 @@ | ||
5 | |||
6 | fi | ||
7 | |||
8 | +cat >> confdefs.h <<\EOF | ||
9 | +#define SUHOSIN_PATCH 1 | ||
10 | +EOF | ||
11 | |||
12 | echo $ac_n "checking for declared timezone""... $ac_c" 1>&6 | ||
13 | echo "configure:18502: checking for declared timezone" >&5 | ||
14 | @@ -115678,7 +115681,7 @@ | ||
15 | php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \ | ||
16 | strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c \ | ||
17 | network.c php_open_temporary_file.c php_logos.c \ | ||
18 | - output.c ; do | ||
19 | + output.c suhosin_patch.c ; do | ||
20 | |||
21 | IFS=. | ||
22 | set $ac_src | ||
23 | @@ -115880,7 +115883,7 @@ | ||
24 | zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \ | ||
25 | zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \ | ||
26 | zend_ini.c zend_qsort.c zend_multibyte.c zend_ts_hash.c zend_stream.c \ | ||
27 | - zend_iterators.c zend_interfaces.c zend_exceptions.c zend_strtod.c; do | ||
28 | + zend_iterators.c zend_interfaces.c zend_exceptions.c zend_strtod.c zend_canary.c; do | ||
29 | |||
30 | IFS=. | ||
31 | set $ac_src | ||
32 | diff -Naur php-5.2.4/configure.in php-5.2.4-suhosin/configure.in | ||
33 | --- php-5.2.4/configure.in 2007-08-30 01:36:11.000000000 +0200 | ||
34 | +++ php-5.2.4-suhosin/configure.in 2007-09-07 20:11:39.000000000 +0200 | ||
35 | @@ -227,6 +227,7 @@ | ||
36 | sinclude(TSRM/threads.m4) | ||
37 | sinclude(TSRM/tsrm.m4) | ||
38 | |||
39 | +sinclude(main/suhosin_patch.m4) | ||
40 | |||
41 | divert(2) | ||
42 | |||
43 | @@ -1301,7 +1302,7 @@ | ||
44 | php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \ | ||
45 | strlcat.c mergesort.c reentrancy.c php_variables.c php_ticks.c \ | ||
46 | network.c php_open_temporary_file.c php_logos.c \ | ||
47 | - output.c ) | ||
48 | + output.c suhosin_patch.c ) | ||
49 | |||
50 | PHP_ADD_SOURCES(main/streams, streams.c cast.c memory.c filter.c \ | ||
51 | plain_wrapper.c userspace.c transports.c xp_socket.c mmap.c) | ||
52 | @@ -1327,7 +1328,7 @@ | ||
53 | zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \ | ||
54 | zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c \ | ||
55 | zend_ini.c zend_qsort.c zend_multibyte.c zend_ts_hash.c zend_stream.c \ | ||
56 | - zend_iterators.c zend_interfaces.c zend_exceptions.c zend_strtod.c) | ||
57 | + zend_iterators.c zend_interfaces.c zend_exceptions.c zend_strtod.c zend_canary.c ) | ||
58 | |||
59 | if test -r "$abs_srcdir/Zend/zend_objects.c"; then | ||
60 | PHP_ADD_SOURCES(Zend, zend_objects.c zend_object_handlers.c zend_objects_API.c \ | ||
61 | diff -Naur php-5.2.4/ext/standard/basic_functions.c php-5.2.4-suhosin/ext/standard/basic_functions.c | ||
62 | --- php-5.2.4/ext/standard/basic_functions.c 2007-08-17 01:05:43.000000000 +0200 | ||
63 | +++ php-5.2.4-suhosin/ext/standard/basic_functions.c 2007-09-07 20:11:39.000000000 +0200 | ||
64 | @@ -3570,7 +3570,9 @@ | ||
65 | PHP_FALIAS(socket_get_status, stream_get_meta_data, arginfo_stream_get_meta_data) | ||
66 | |||
67 | #if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS) | ||
68 | - PHP_FE(realpath, arginfo_realpath) | ||
69 | +#undef realpath | ||
70 | + PHP_NAMED_FE(realpath, PHP_FN(real_path), arginfo_realpath) | ||
71 | +#define realpath real_path | ||
72 | #endif | ||
73 | |||
74 | #ifdef HAVE_FNMATCH | ||
75 | diff -Naur php-5.2.4/ext/standard/dl.c php-5.2.4-suhosin/ext/standard/dl.c | ||
76 | --- php-5.2.4/ext/standard/dl.c 2007-02-23 01:37:35.000000000 +0100 | ||
77 | +++ php-5.2.4-suhosin/ext/standard/dl.c 2007-09-07 20:11:39.000000000 +0200 | ||
78 | @@ -233,6 +233,19 @@ | ||
79 | RETURN_FALSE; | ||
80 | } | ||
81 | } | ||
82 | +#if SUHOSIN_PATCH | ||
83 | + if (strncmp("suhosin", module_entry->name, sizeof("suhosin")-1) == 0) { | ||
84 | + void *log_func; | ||
85 | + /* sucessfully loaded suhosin extension, now check for logging function replacement */ | ||
86 | + log_func = (void *) DL_FETCH_SYMBOL(handle, "suhosin_log"); | ||
87 | + if (log_func == NULL) { | ||
88 | + log_func = (void *) DL_FETCH_SYMBOL(handle, "_suhosin_log"); | ||
89 | + } | ||
90 | + if (log_func != NULL) { | ||
91 | + zend_suhosin_log = log_func; | ||
92 | + } | ||
93 | + } | ||
94 | +#endif | ||
95 | RETURN_TRUE; | ||
96 | } | ||
97 | /* }}} */ | ||
98 | diff -Naur php-5.2.4/ext/standard/file.c php-5.2.4-suhosin/ext/standard/file.c | ||
99 | --- php-5.2.4/ext/standard/file.c 2007-08-12 19:09:59.000000000 +0200 | ||
100 | +++ php-5.2.4-suhosin/ext/standard/file.c 2007-09-07 20:11:39.000000000 +0200 | ||
101 | @@ -2361,7 +2361,7 @@ | ||
102 | #if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS) | ||
103 | /* {{{ proto string realpath(string path) | ||
104 | Return the resolved path */ | ||
105 | -PHP_FUNCTION(realpath) | ||
106 | +PHP_FUNCTION(real_path) | ||
107 | { | ||
108 | zval **path; | ||
109 | char resolved_path_buff[MAXPATHLEN]; | ||
110 | diff -Naur php-5.2.4/ext/standard/file.h php-5.2.4-suhosin/ext/standard/file.h | ||
111 | --- php-5.2.4/ext/standard/file.h 2007-01-10 15:40:06.000000000 +0100 | ||
112 | +++ php-5.2.4-suhosin/ext/standard/file.h 2007-09-07 20:11:39.000000000 +0200 | ||
113 | @@ -61,7 +61,7 @@ | ||
114 | PHP_FUNCTION(fd_set); | ||
115 | PHP_FUNCTION(fd_isset); | ||
116 | #if (!defined(__BEOS__) && !defined(NETWARE) && HAVE_REALPATH) || defined(ZTS) | ||
117 | -PHP_FUNCTION(realpath); | ||
118 | +PHP_FUNCTION(real_path); | ||
119 | #endif | ||
120 | #ifdef HAVE_FNMATCH | ||
121 | PHP_FUNCTION(fnmatch); | ||
122 | diff -Naur php-5.2.4/ext/standard/info.c php-5.2.4-suhosin/ext/standard/info.c | ||
123 | --- php-5.2.4/ext/standard/info.c 2007-07-21 03:24:26.000000000 +0200 | ||
124 | +++ php-5.2.4-suhosin/ext/standard/info.c 2007-09-07 20:11:39.000000000 +0200 | ||
125 | @@ -627,6 +627,31 @@ | ||
126 | |||
127 | php_info_print_table_end(); | ||
128 | |||
129 | + /* Suhosin Patch */ | ||
130 | + php_info_print_box_start(0); | ||
131 | + if (expose_php && !sapi_module.phpinfo_as_text) { | ||
132 | + PUTS("<a href=\"http://www.hardened-php.net/suhosin/index.html\"><img border=\"0\" src=\""); | ||
133 | + if (SG(request_info).request_uri) { | ||
134 | + char *elem_esc = php_info_html_esc(SG(request_info).request_uri TSRMLS_CC); | ||
135 | + PUTS(elem_esc); | ||
136 | + efree(elem_esc); | ||
137 | + } | ||
138 | + PUTS("?="SUHOSIN_LOGO_GUID"\" alt=\"Suhosin logo\" /></a>\n"); | ||
139 | + } | ||
140 | + PUTS("This server is protected with the Suhosin Patch "); | ||
141 | + if (sapi_module.phpinfo_as_text) { | ||
142 | + PUTS(SUHOSIN_PATCH_VERSION); | ||
143 | + } else { | ||
144 | + zend_html_puts(SUHOSIN_PATCH_VERSION, strlen(SUHOSIN_PATCH_VERSION) TSRMLS_CC); | ||
145 | + } | ||
146 | + PUTS(!sapi_module.phpinfo_as_text?"<br />":"\n"); | ||
147 | + if (sapi_module.phpinfo_as_text) { | ||
148 | + PUTS("Copyright (c) 2006 Hardened-PHP Project\n"); | ||
149 | + } else { | ||
150 | + PUTS("Copyright (c) 2006 <a href=\"http://www.hardened-php.net/\">Hardened-PHP Project</a>\n"); | ||
151 | + } | ||
152 | + php_info_print_box_end(); | ||
153 | + | ||
154 | /* Zend Engine */ | ||
155 | php_info_print_box_start(0); | ||
156 | if (expose_php && !sapi_module.phpinfo_as_text) { | ||
157 | diff -Naur php-5.2.4/ext/standard/syslog.c php-5.2.4-suhosin/ext/standard/syslog.c | ||
158 | --- php-5.2.4/ext/standard/syslog.c 2007-05-17 08:38:13.000000000 +0200 | ||
159 | +++ php-5.2.4-suhosin/ext/standard/syslog.c 2007-09-07 20:11:39.000000000 +0200 | ||
160 | @@ -42,6 +42,7 @@ | ||
161 | */ | ||
162 | PHP_MINIT_FUNCTION(syslog) | ||
163 | { | ||
164 | +#if !SUHOSIN_PATCH | ||
165 | /* error levels */ | ||
166 | REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */ | ||
167 | REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */ | ||
168 | @@ -97,6 +98,7 @@ | ||
169 | /* AIX doesn't have LOG_PERROR */ | ||
170 | REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/ | ||
171 | #endif | ||
172 | +#endif | ||
173 | BG(syslog_device)=NULL; | ||
174 | |||
175 | return SUCCESS; | ||
176 | diff -Naur php-5.2.4/main/fopen_wrappers.c php-5.2.4-suhosin/main/fopen_wrappers.c | ||
177 | --- php-5.2.4/main/fopen_wrappers.c 2007-07-10 15:21:11.000000000 +0200 | ||
178 | +++ php-5.2.4-suhosin/main/fopen_wrappers.c 2007-09-07 20:17:05.000000000 +0200 | ||
179 | @@ -111,7 +111,7 @@ | ||
180 | |||
181 | /* normalize and expand path */ | ||
182 | if (expand_filepath(path, resolved_name TSRMLS_CC) == NULL) { | ||
183 | - return -1; | ||
184 | + return -2; | ||
185 | } | ||
186 | |||
187 | path_len = strlen(resolved_name); | ||
188 | @@ -180,6 +180,12 @@ | ||
189 | } | ||
190 | } | ||
191 | |||
192 | + if (resolved_name_len == resolved_basedir_len - 1) { | ||
193 | + if (resolved_basedir[resolved_basedir_len - 1] == PHP_DIR_SEPARATOR) { | ||
194 | + resolved_basedir_len--; | ||
195 | + } | ||
196 | + } | ||
197 | + | ||
198 | /* Check the path */ | ||
199 | #if defined(PHP_WIN32) || defined(NETWARE) | ||
200 | if (strncasecmp(resolved_basedir, resolved_name, resolved_basedir_len) == 0) { | ||
201 | @@ -203,7 +209,7 @@ | ||
202 | } | ||
203 | } else { | ||
204 | /* Unable to resolve the real path, return -1 */ | ||
205 | - return -1; | ||
206 | + return -3; | ||
207 | } | ||
208 | } | ||
209 | /* }}} */ | ||
210 | @@ -222,22 +228,44 @@ | ||
211 | char *pathbuf; | ||
212 | char *ptr; | ||
213 | char *end; | ||
214 | + char path_copy[MAXPATHLEN]; | ||
215 | + int path_len; | ||
216 | + | ||
217 | + /* Special case path ends with a trailing slash */ | ||
218 | + path_len = strlen(path); | ||
219 | + if (path_len >= MAXPATHLEN) { | ||
220 | + errno = EPERM; /* we deny permission to open it */ | ||
221 | + return -1; | ||
222 | + } | ||
223 | + if (path_len > 0 && path[path_len-1] == PHP_DIR_SEPARATOR) { | ||
224 | + memcpy(path_copy, path, path_len+1); | ||
225 | + while (path_len > 0 && path_copy[path_len-1] == PHP_DIR_SEPARATOR) path_len--; | ||
226 | + path_copy[path_len] = '\0'; | ||
227 | + path = (const char *)&path_copy; | ||
228 | + } | ||
229 | |||
230 | pathbuf = estrdup(PG(open_basedir)); | ||
231 | |||
232 | ptr = pathbuf; | ||
233 | |||
234 | while (ptr && *ptr) { | ||
235 | + int res; | ||
236 | end = strchr(ptr, DEFAULT_DIR_SEPARATOR); | ||
237 | if (end != NULL) { | ||
238 | *end = '\0'; | ||
239 | end++; | ||
240 | } | ||
241 | |||
242 | - if (php_check_specific_open_basedir(ptr, path TSRMLS_CC) == 0) { | ||
243 | + res = php_check_specific_open_basedir(ptr, path TSRMLS_CC); | ||
244 | + if (res == 0) { | ||
245 | efree(pathbuf); | ||
246 | return 0; | ||
247 | } | ||
248 | + if (res == -2) { | ||
249 | + efree(pathbuf); | ||
250 | + errno = EPERM; | ||
251 | + return -1; | ||
252 | + } | ||
253 | |||
254 | ptr = end; | ||
255 | } | ||
256 | diff -Naur php-5.2.4/main/main.c php-5.2.4-suhosin/main/main.c | ||
257 | --- php-5.2.4/main/main.c 2007-08-03 03:30:21.000000000 +0200 | ||
258 | +++ php-5.2.4-suhosin/main/main.c 2007-09-07 20:11:39.000000000 +0200 | ||
259 | @@ -88,6 +88,9 @@ | ||
260 | |||
261 | #include "SAPI.h" | ||
262 | #include "rfc1867.h" | ||
263 | +#if SUHOSIN_PATCH | ||
264 | +#include "suhosin_globals.h" | ||
265 | +#endif | ||
266 | /* }}} */ | ||
267 | |||
268 | #ifndef ZTS | ||
269 | @@ -1347,7 +1350,7 @@ | ||
270 | |||
271 | /* used to close fd's in the 3..255 range here, but it's problematic | ||
272 | */ | ||
273 | - shutdown_memory_manager(1, 1 TSRMLS_CC); | ||
274 | + shutdown_memory_manager(1, 1 TSRMLS_CC); | ||
275 | } | ||
276 | /* }}} */ | ||
277 | |||
278 | @@ -1388,6 +1391,9 @@ | ||
279 | |||
280 | zend_try { | ||
281 | shutdown_memory_manager(CG(unclean_shutdown), 0 TSRMLS_CC); | ||
282 | +#if SUHOSIN_PATCH | ||
283 | + suhosin_clear_mm_canaries(TSRMLS_C); | ||
284 | +#endif | ||
285 | } zend_end_try(); | ||
286 | |||
287 | zend_try { | ||
288 | @@ -1480,6 +1486,9 @@ | ||
289 | /* 11. Free Willy (here be crashes) */ | ||
290 | zend_try { | ||
291 | shutdown_memory_manager(CG(unclean_shutdown) || !report_memleaks, 0 TSRMLS_CC); | ||
292 | +#if SUHOSIN_PATCH | ||
293 | + suhosin_clear_mm_canaries(TSRMLS_C); | ||
294 | +#endif | ||
295 | } zend_end_try(); | ||
296 | |||
297 | /* 12. Reset max_execution_time */ | ||
298 | @@ -1639,6 +1648,9 @@ | ||
299 | #ifdef ZTS | ||
300 | tsrm_ls = ts_resource(0); | ||
301 | #endif | ||
302 | +#if SUHOSIN_PATCH | ||
303 | + suhosin_startup(); | ||
304 | +#endif | ||
305 | |||
306 | module_shutdown = 0; | ||
307 | module_startup = 1; | ||
308 | @@ -1768,6 +1780,10 @@ | ||
309 | REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_PATH", PHP_CONFIG_FILE_PATH, strlen(PHP_CONFIG_FILE_PATH), CONST_PERSISTENT | CONST_CS); | ||
310 | REGISTER_MAIN_STRINGL_CONSTANT("PHP_CONFIG_FILE_SCAN_DIR", PHP_CONFIG_FILE_SCAN_DIR, sizeof(PHP_CONFIG_FILE_SCAN_DIR)-1, CONST_PERSISTENT | CONST_CS); | ||
311 | REGISTER_MAIN_STRINGL_CONSTANT("PHP_SHLIB_SUFFIX", PHP_SHLIB_SUFFIX, sizeof(PHP_SHLIB_SUFFIX)-1, CONST_PERSISTENT | CONST_CS); | ||
312 | +#if SUHOSIN_PATCH | ||
313 | + REGISTER_MAIN_LONG_CONSTANT("SUHOSIN_PATCH", 1, CONST_PERSISTENT | CONST_CS); | ||
314 | + REGISTER_MAIN_STRINGL_CONSTANT("SUHOSIN_PATCH_VERSION", SUHOSIN_PATCH_VERSION, sizeof(SUHOSIN_PATCH_VERSION)-1, CONST_PERSISTENT | CONST_CS); | ||
315 | +#endif | ||
316 | REGISTER_MAIN_STRINGL_CONSTANT("PHP_EOL", PHP_EOL, sizeof(PHP_EOL)-1, CONST_PERSISTENT | CONST_CS); | ||
317 | REGISTER_MAIN_LONG_CONSTANT("PHP_INT_MAX", LONG_MAX, CONST_PERSISTENT | CONST_CS); | ||
318 | REGISTER_MAIN_LONG_CONSTANT("PHP_INT_SIZE", sizeof(long), CONST_PERSISTENT | CONST_CS); | ||
319 | @@ -1817,7 +1833,9 @@ | ||
320 | module_startup = 0; | ||
321 | |||
322 | shutdown_memory_manager(1, 0 TSRMLS_CC); | ||
323 | - | ||
324 | +#if SUHOSIN_PATCH | ||
325 | + suhosin_clear_mm_canaries(TSRMLS_C); | ||
326 | +#endif | ||
327 | /* we're done */ | ||
328 | return SUCCESS; | ||
329 | } | ||
330 | @@ -1876,6 +1894,9 @@ | ||
331 | #ifndef ZTS | ||
332 | zend_ini_shutdown(TSRMLS_C); | ||
333 | shutdown_memory_manager(CG(unclean_shutdown), 1 TSRMLS_CC); | ||
334 | +#if SUHOSIN_PATCH | ||
335 | + suhosin_clear_mm_canaries(TSRMLS_C); | ||
336 | +#endif | ||
337 | core_globals_dtor(&core_globals TSRMLS_CC); | ||
338 | #else | ||
339 | zend_ini_global_shutdown(TSRMLS_C); | ||
340 | diff -Naur php-5.2.4/main/php_config.h.in php-5.2.4-suhosin/main/php_config.h.in | ||
341 | --- php-5.2.4/main/php_config.h.in 2007-08-30 01:39:22.000000000 +0200 | ||
342 | +++ php-5.2.4-suhosin/main/php_config.h.in 2007-09-07 20:11:39.000000000 +0200 | ||
343 | @@ -803,6 +803,9 @@ | ||
344 | /* Define if the target system has /dev/urandom device */ | ||
345 | #undef HAVE_DEV_URANDOM | ||
346 | |||
347 | +/* Suhosin-Patch for PHP */ | ||
348 | +#undef SUHOSIN_PATCH | ||
349 | + | ||
350 | /* Whether you have AOLserver */ | ||
351 | #undef HAVE_AOLSERVER | ||
352 | |||
353 | diff -Naur php-5.2.4/main/php.h php-5.2.4-suhosin/main/php.h | ||
354 | --- php-5.2.4/main/php.h 2007-01-01 10:36:11.000000000 +0100 | ||
355 | +++ php-5.2.4-suhosin/main/php.h 2007-09-07 20:11:39.000000000 +0200 | ||
356 | @@ -40,6 +40,13 @@ | ||
357 | #undef sprintf | ||
358 | #define sprintf php_sprintf | ||
359 | |||
360 | +#if SUHOSIN_PATCH | ||
361 | +#if HAVE_REALPATH | ||
362 | +#undef realpath | ||
363 | +#define realpath php_realpath | ||
364 | +#endif | ||
365 | +#endif | ||
366 | + | ||
367 | /* PHP's DEBUG value must match Zend's ZEND_DEBUG value */ | ||
368 | #undef PHP_DEBUG | ||
369 | #define PHP_DEBUG ZEND_DEBUG | ||
370 | @@ -452,6 +459,10 @@ | ||
371 | #endif | ||
372 | #endif /* !XtOffsetOf */ | ||
373 | |||
374 | +#if SUHOSIN_PATCH | ||
375 | +#include "suhosin_patch.h" | ||
376 | +#endif | ||
377 | + | ||
378 | #endif | ||
379 | |||
380 | /* | ||
381 | diff -Naur php-5.2.4/main/php_logos.c php-5.2.4-suhosin/main/php_logos.c | ||
382 | --- php-5.2.4/main/php_logos.c 2007-01-06 21:44:51.000000000 +0100 | ||
383 | +++ php-5.2.4-suhosin/main/php_logos.c 2007-09-07 20:11:39.000000000 +0200 | ||
384 | @@ -50,6 +50,10 @@ | ||
385 | return zend_hash_del(&phpinfo_logo_hash, logo_string, strlen(logo_string)); | ||
386 | } | ||
387 | |||
388 | +#if SUHOSIN_PATCH | ||
389 | +#include "suhosin_logo.h" | ||
390 | +#endif | ||
391 | + | ||
392 | int php_init_info_logos(void) | ||
393 | { | ||
394 | if(zend_hash_init(&phpinfo_logo_hash, 0, NULL, NULL, 1)==FAILURE) | ||
395 | @@ -58,6 +62,9 @@ | ||
396 | php_register_info_logo(PHP_LOGO_GUID , "image/gif", php_logo , sizeof(php_logo)); | ||
397 | php_register_info_logo(PHP_EGG_LOGO_GUID, "image/gif", php_egg_logo, sizeof(php_egg_logo)); | ||
398 | php_register_info_logo(ZEND_LOGO_GUID , "image/gif", zend_logo , sizeof(zend_logo)); | ||
399 | +#if SUHOSIN_PATCH | ||
400 | + php_register_info_logo(SUHOSIN_LOGO_GUID, "image/jpeg", suhosin_logo, sizeof(suhosin_logo)); | ||
401 | +#endif | ||
402 | |||
403 | return SUCCESS; | ||
404 | } | ||
405 | diff -Naur php-5.2.4/main/snprintf.c php-5.2.4-suhosin/main/snprintf.c | ||
406 | --- php-5.2.4/main/snprintf.c 2007-08-03 16:31:27.000000000 +0200 | ||
407 | +++ php-5.2.4-suhosin/main/snprintf.c 2007-09-07 20:11:39.000000000 +0200 | ||
408 | @@ -1079,7 +1079,11 @@ | ||
409 | |||
410 | |||
411 | case 'n': | ||
412 | +#if SUHOSIN_PATCH | ||
413 | + zend_suhosin_log(S_MISC, "'n' specifier within format string"); | ||
414 | +#else | ||
415 | *(va_arg(ap, int *)) = cc; | ||
416 | +#endif | ||
417 | goto skip_output; | ||
418 | |||
419 | /* | ||
420 | diff -Naur php-5.2.4/main/spprintf.c php-5.2.4-suhosin/main/spprintf.c | ||
421 | --- php-5.2.4/main/spprintf.c 2007-08-03 16:31:28.000000000 +0200 | ||
422 | +++ php-5.2.4-suhosin/main/spprintf.c 2007-09-07 20:11:39.000000000 +0200 | ||
423 | @@ -672,7 +672,11 @@ | ||
424 | |||
425 | |||
426 | case 'n': | ||
427 | +#if SUHOSIN_PATCH | ||
428 | + zend_suhosin_log(S_MISC, "'n' specifier within format string"); | ||
429 | +#else | ||
430 | *(va_arg(ap, int *)) = xbuf->len; | ||
431 | +#endif | ||
432 | goto skip_output; | ||
433 | |||
434 | /* | ||
435 | diff -Naur php-5.2.4/main/suhosin_globals.h php-5.2.4-suhosin/main/suhosin_globals.h | ||
436 | --- php-5.2.4/main/suhosin_globals.h 1970-01-01 01:00:00.000000000 +0100 | ||
437 | +++ php-5.2.4-suhosin/main/suhosin_globals.h 2007-09-07 20:11:39.000000000 +0200 | ||
438 | @@ -0,0 +1,61 @@ | ||
439 | +/* | ||
440 | + +----------------------------------------------------------------------+ | ||
441 | + | Suhosin-Patch for PHP | | ||
442 | + +----------------------------------------------------------------------+ | ||
443 | + | Copyright (c) 2004-2006 Stefan Esser | | ||
444 | + +----------------------------------------------------------------------+ | ||
445 | + | This source file is subject to version 2.02 of the PHP license, | | ||
446 | + | that is bundled with this package in the file LICENSE, and is | | ||
447 | + | available at through the world-wide-web at | | ||
448 | + | http://www.php.net/license/2_02.txt. | | ||
449 | + | If you did not receive a copy of the PHP license and are unable to | | ||
450 | + | obtain it through the world-wide-web, please send a note to | | ||
451 | + | license@php.net so we can mail you a copy immediately. | | ||
452 | + +----------------------------------------------------------------------+ | ||
453 | + | Author: Stefan Esser <sesser@hardened-php.net> | | ||
454 | + +----------------------------------------------------------------------+ | ||
455 | + */ | ||
456 | + | ||
457 | +#ifndef SUHOSIN_GLOBALS_H | ||
458 | +#define SUHOSIN_GLOBALS_H | ||
459 | + | ||
460 | +typedef struct _suhosin_patch_globals suhosin_patch_globals_struct; | ||
461 | + | ||
462 | +#ifdef ZTS | ||
463 | +# define SPG(v) TSRMG(suhosin_patch_globals_id, suhosin_patch_globals_struct *, v) | ||
464 | +extern int suhosin_patch_globals_id; | ||
465 | +#else | ||
466 | +# define SPG(v) (suhosin_patch_globals.v) | ||
467 | +extern struct _suhosin_patch_globals suhosin_patch_globals; | ||
468 | +#endif | ||
469 | + | ||
470 | + | ||
471 | +struct _suhosin_patch_globals { | ||
472 | + /* logging */ | ||
473 | + int log_syslog; | ||
474 | + int log_syslog_facility; | ||
475 | + int log_syslog_priority; | ||
476 | + int log_sapi; | ||
477 | + int log_script; | ||
478 | + int log_phpscript; | ||
479 | + char *log_scriptname; | ||
480 | + char *log_phpscriptname; | ||
481 | + zend_bool log_phpscript_is_safe; | ||
482 | + zend_bool log_use_x_forwarded_for; | ||
483 | + | ||
484 | + /* memory manager canary protection */ | ||
485 | + unsigned int canary_1; | ||
486 | + unsigned int canary_2; | ||
487 | + unsigned int canary_3; | ||
488 | + unsigned int dummy; | ||
489 | +}; | ||
490 | + | ||
491 | + | ||
492 | +#endif /* SUHOSIN_GLOBALS_H */ | ||
493 | + | ||
494 | +/* | ||
495 | + * Local variables: | ||
496 | + * tab-width: 4 | ||
497 | + * c-basic-offset: 4 | ||
498 | + * End: | ||
499 | + */ | ||
500 | diff -Naur php-5.2.4/main/suhosin_logo.h php-5.2.4-suhosin/main/suhosin_logo.h | ||
501 | --- php-5.2.4/main/suhosin_logo.h 1970-01-01 01:00:00.000000000 +0100 | ||
502 | +++ php-5.2.4-suhosin/main/suhosin_logo.h 2007-09-07 20:11:39.000000000 +0200 | ||
503 | @@ -0,0 +1,178 @@ | ||
504 | +static unsigned char suhosin_logo[] = | ||
505 | + "\xff\xd8\xff\xe0\x00\x10\x4a\x46\x49\x46\x00\x01\x01\x01\x00\x48" | ||
506 | + "\x00\x48\x00\x00\xff\xe1\x00\x16\x45\x78\x69\x66\x00\x00\x4d\x4d" | ||
507 | + "\x00\x2a\x00\x00\x00\x08\x00\x00\x00\x00\x00\x00\xff\xdb\x00\x43" | ||
508 | + "\x00\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" | ||
509 | + "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" | ||
510 | + "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" | ||
511 | + "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" | ||
512 | + "\x01\xff\xc0\x00\x0b\x08\x00\x27\x00\x71\x01\x01\x22\x00\xff\xc4" | ||
513 | + "\x00\x1e\x00\x00\x02\x02\x02\x03\x01\x01\x00\x00\x00\x00\x00\x00" | ||
514 | + "\x00\x00\x00\x00\x09\x06\x08\x05\x07\x02\x03\x0a\x01\x04\xff\xc4" | ||
515 | + "\x00\x32\x10\x00\x01\x04\x03\x00\x02\x00\x05\x01\x05\x09\x01\x00" | ||
516 | + "\x00\x00\x00\x05\x02\x03\x04\x06\x01\x07\x08\x00\x09\x11\x12\x13" | ||
517 | + "\x14\x21\x15\x0a\x16\x31\x56\x96\x17\x18\x19\x23\x32\x41\x58\x98" | ||
518 | + "\xd4\xd6\xff\xda\x00\x08\x01\x01\x00\x00\x3f\x00\xf4\xc1\xe1\xe5" | ||
519 | + "\x69\xe9\x3e\xb9\xd1\x7c\x8a\x2e\x9d\x66\xe8\x3b\x29\x4d\x7f\x46" | ||
520 | + "\xba\x58\x55\x54\x8d\xb1\x5f\xaa\xd9\x8d\x51\x2b\xb6\x27\x5a\x69" | ||
521 | + "\xd1\x43\xaf\x16\x1a\xf0\xb2\xb1\xe9\x6d\x9f\xc2\xa4\x36\x18\xb5" | ||
522 | + "\x85\x10\x41\xbe\xfc\x09\xac\x49\x29\x11\xd4\x32\x97\xec\x08\x13" | ||
523 | + "\xc1\x2d\x20\xc3\x59\xeb\x26\x05\xd8\x6b\x76\x31\x43\x8f\x57\xcf" | ||
524 | + "\x84\x9f\x14\xa8\x53\x81\x0b\xc3\x64\x80\xa3\x02\x0a\x41\x75\xf8" | ||
525 | + "\x44\x85\x93\x81\x22\x3c\xd8\x13\xe1\xbe\xf4\x59\x91\x1f\x6a\x44" | ||
526 | + "\x77\x5c\x69\xc4\x2f\x39\x5f\x0f\x2a\x8d\xeb\xba\xf8\xc3\x56\x6c" | ||
527 | + "\x3b\x36\xa7\xda\xbd\x4d\xa1\xb5\x4e\xc6\xa7\xa4\x3a\xec\x15\x2d" | ||
528 | + "\xa5\xb3\xea\x5a\xdc\xac\x46\xac\x01\x60\xd8\x43\xc8\x8e\x8b\xb1" | ||
529 | + "\x40\x4c\x95\x8b\x34\x41\x28\x52\x91\x28\x43\xd3\xa3\xb6\xa7\x55" | ||
530 | + "\x15\xe7\x5a\x96\xcb\xf1\xda\xe5\x55\xee\xfe\x1e\xbd\xd9\x41\xd3" | ||
531 | + "\x28\xfd\x97\xca\x57\x2b\x85\x9c\xa4\x30\x95\xaa\xa5\x57\xa2\x35" | ||
532 | + "\x15\x86\xcb\x61\x34\x41\xe4\xc7\x80\x20\x18\x21\x17\x09\x85\x0b" | ||
533 | + "\x14\x9d\x21\x68\x62\x1c\x08\x11\x64\x4b\x92\xf2\xd2\xd3\x2d\x2d" | ||
534 | + "\x6a\xc2\x73\x6b\x3c\x3c\x8b\x9e\xbc\x52\xaa\xa4\xab\x81\x6c\xf6" | ||
535 | + "\xfa\xbd\x70\xc5\xc6\x7b\xc2\xaa\x22\x4f\x58\x04\x87\x25\x6a\x27" | ||
536 | + "\x1d\xa4\x3d\x20\x75\x72\x01\x09\x71\xe5\x1c\x9e\xc3\x2e\x36\xf3" | ||
537 | + "\xd0\xc6\x35\x2a\x43\x4d\x2d\x0e\x2d\xb4\xa1\x49\xce\x65\x1e\x52" | ||
538 | + "\x9e\xa1\xf6\x09\xcc\xdc\x63\x66\xa8\x01\xe9\x3b\x0d\xd7\x5a\x85" | ||
539 | + "\xbb\xc5\x65\xc0\x7b\x2e\x46\xa9\xd9\x56\x1d\x4c\x92\x72\x26\x4e" | ||
540 | + "\x86\xd5\x68\xae\xc4\xaa\x55\xce\xd7\x83\x59\xb3\x81\xee\xce\x74" | ||
541 | + "\x39\x39\x31\x9f\x8a\x25\xe8\xa5\xa5\xe5\x81\xf2\x11\x23\xcb\xa1" | ||
542 | + "\x1e\x43\x12\xe3\xb1\x2a\x2b\xcd\xc8\x8d\x25\x96\xa4\x47\x7d\x95" | ||
543 | + "\xa5\xc6\x9f\x61\xe4\x25\xc6\x5e\x69\xc4\xe7\x29\x5b\x6e\xb6\xa4" | ||
544 | + "\xad\x0b\x4e\x72\x95\x25\x58\x56\x33\x9c\x67\xce\xef\x0f\x17\xbf" | ||
545 | + "\x4c\x7b\x2d\xe6\xfe\x76\x35\x27\x5a\x07\x97\x67\xe8\xae\x8d\x71" | ||
546 | + "\x0f\xb2\x13\x99\xb9\xbc\x14\xad\xb3\xb7\xe6\x11\x6f\xe0\xda\x58" | ||
547 | + "\xb1\x08\xac\xa6\x6c\x2d\x7f\x05\xb7\x56\xd2\xe6\xcf\xbb\x4d\x0c" | ||
548 | + "\xe3\x50\xb2\xec\x91\xf0\x4a\xb8\xd6\x22\xb8\xa7\xf6\x67\xaf\xcf" | ||
549 | + "\x63\x7e\xd7\xe7\x42\xd8\xbd\xc3\x71\xa1\xf2\x7e\x9b\xa8\x97\x83" | ||
550 | + "\x6e\xd1\xdc\x4b\x06\x11\x2d\xae\x26\x61\x98\x72\x10\xf4\x42\x5d" | ||
551 | + "\x20\x4a\xa3\x73\xd7\xf2\xcd\x3c\x48\x32\xe4\x03\x9f\x80\x37\x08" | ||
552 | + "\x36\x11\xd0\xcb\x97\x6c\x08\xed\x6d\x33\x24\xa2\x1b\xb4\x77\xdf" | ||
553 | + "\x61\x5d\x5f\xc1\x43\xc2\x82\xeb\x0f\x5d\x84\x08\x68\xaa\xa4\x01" | ||
554 | + "\xe1\x19\xdf\xbc\x31\x65\xfe\xd1\xf5\x7d\x7a\xb2\x2a\x33\x50\x21" | ||
555 | + "\x2a\x56\x9d\xb1\x81\xab\xdb\x35\x78\x30\x83\xd9\x89\x1d\x31\xac" | ||
556 | + "\x96\x14\x07\x61\xbc\x20\x68\x42\x85\x33\x19\xac\xbe\xdb\x34\x56" | ||
557 | + "\xf1\xd5\xfd\x29\xa9\x28\xdb\xcb\x4c\x5a\x23\xdc\xf5\x96\xc5\x10" | ||
558 | + "\xa3\x35\x5b\x14\x68\xd3\x61\x62\x64\x76\x26\xcb\x17\x3e\x34\x98" | ||
559 | + "\x04\xa3\xc4\x20\x38\x90\x92\xe3\xc8\x07\x2c\x36\x74\x66\x26\x0e" | ||
560 | + "\x29\x02\x64\x29\x2d\x21\xe6\x16\x9c\x6b\xce\xa3\x89\xd9\x4f\xd3" | ||
561 | + "\xc4\xbd\xc5\x87\x79\x9c\x65\xf6\x39\x45\x60\xe8\xce\x9e\xab\x6d" | ||
562 | + "\x13\x15\x22\xe1\x5e\x4b\x38\x42\xc4\x1e\xd5\x76\xe0\xc5\xeb\x85" | ||
563 | + "\x07\x2d\x0f\xb8\xb6\xa6\xd6\x6d\x71\x0d\xa2\x43\x4c\x25\xea\xfa" | ||
564 | + "\xa1\xae\x4c\xe4\x7d\xbd\x76\xa9\xfb\x06\xc2\x83\x42\xeb\xad\xe7" | ||
565 | + "\xe9\x5f\x68\x6f\xba\xfb\x2f\x07\xce\xb8\x13\xc1\x9b\xeb\xb0\x76" | ||
566 | + "\x45\x57\x28\x7b\xea\xbe\x0f\xf4\x30\x7b\xa0\xed\xe4\x22\x93\x21" | ||
567 | + "\xfc\xbc\xe0\xb9\x75\xc1\x4f\xfc\xef\xb6\xfa\xa1\xfc\x64\xa1\x4a" | ||
568 | + "\x82\xc7\x33\xad\x75\xed\x82\xbd\x3d\xdb\xf7\xa8\xbe\x5e\xbb\x36" | ||
569 | + "\x62\x04\x9a\x2e\xc5\xd9\x9e\x9c\x3a\x0b\x98\x0b\x57\xac\xf1\x24" | ||
570 | + "\x62\x58\x83\x15\x5b\xa6\xf2\xda\x34\x70\x03\xce\x0f\x93\x1b\x12" | ||
571 | + "\xc7\xce\x54\x87\x33\x15\xd6\x53\x25\x1f\x2a\x90\x87\x12\xe3\x78" | ||
572 | + "\xef\x55\x77\x4d\x4a\xd8\x7e\xef\xd2\xfd\xd1\xaf\x3a\xaf\x55\xdb" | ||
573 | + "\x6a\x2d\x3d\x42\xac\x51\x79\xee\x91\xab\xe1\x05\x2d\x3c\x80\xa2" | ||
574 | + "\x43\xad\x22\x2e\xd5\x33\x13\xa4\x9e\x00\xe0\x04\x10\x84\xc8\xf2" | ||
575 | + "\x19\x30\x92\x1f\xaa\xc3\x28\xc9\x76\x30\x3f\xe9\x10\x61\x5e\x79" | ||
576 | + "\xd5\xf7\xdf\xd0\x54\xdb\xae\xb6\xae\xfa\xe8\xa3\x57\xe0\x6c\x2d" | ||
577 | + "\xf7\xbd\x49\xd6\x6e\x76\x79\xcc\x54\x0c\x5f\xff\x00\xbb\x06\x98" | ||
578 | + "\xa6\x9e\x89\x61\xb4\x6f\xc3\xe3\x6a\xc2\x4f\x59\x03\xc9\x80\x2c" | ||
579 | + "\x59\x24\x44\x70\x38\xd5\x96\x6a\x9e\x8b\x81\x64\xe5\xbc\xa0\x3c" | ||
580 | + "\x33\xaf\x17\x9d\xff\x00\x71\x1a\xd1\x3a\x80\x66\xb3\xd9\x31\x77" | ||
581 | + "\x0d\x12\xbd\xae\x29\xb5\x6a\xd6\xcf\x8d\x68\x87\x75\xcd\xe8\x65" | ||
582 | + "\x5a\xbe\x3c\x04\x7b\x34\xdb\x54\x19\xa4\x63\x9c\x2a\x5d\x23\xbe" | ||
583 | + "\xf4\xb1\x1c\x4d\x90\xec\x92\x2f\x49\x71\xf7\x14\xf2\x97\x9f\x15" | ||
584 | + "\x57\xed\x13\x21\x2a\xf5\x33\xd1\x2a\x52\x52\xac\xb7\x62\xd1\xcb" | ||
585 | + "\x46\x73\x8c\x67\x28\x56\x77\x86\xbf\x6f\x2a\x4e\x73\xfe\x95\x65" | ||
586 | + "\x0b\x5a\x3e\x38\xfc\xfc\xaa\x56\x3f\x86\x73\xe3\xb9\x4a\x52\x84" | ||
587 | + "\xa5\x08\x4e\x12\x94\x27\x09\x4a\x53\x8c\x61\x29\x4a\x71\xf0\x4a" | ||
588 | + "\x53\x8c\x7e\x31\x8c\x63\x18\xc6\x31\x8f\xc6\x31\xf8\xc7\x9f\x7c" | ||
589 | + "\xd5\xbb\xae\x5e\xe2\x1f\xab\x6e\x24\x34\x00\x8a\x25\x83\x70\x40" | ||
590 | + "\x1c\xcc\xda\x45\x7f\x66\x4e\x30\x2e\x94\x7e\x74\x49\xf0\xe4\x4e" | ||
591 | + "\x06\x5c\xa8\x2f\x89\x21\x2e\x98\x0e\xd9\x21\xc2\x0b\x21\x0f\xc4" | ||
592 | + "\x16\x6e\x48\xd9\xe4\xe3\x4a\x19\x1e\x64\x67\x54\xff\x00\x3a\x6d" | ||
593 | + "\x4f\x62\xb5\x00\x4a\xaa\x51\xfd\x2d\xe8\x0e\x6c\xaf\xc6\x7d\x6d" | ||
594 | + "\xc8\x88\xc7\x67\xea\x8a\x58\x02\x73\xe3\x65\x4d\xc9\x24\xc0\x3d" | ||
595 | + "\x57\xa3\x2e\x53\x16\x99\x4f\xe5\xe7\x19\x97\x3e\x3b\xcf\xc9\x4b" | ||
596 | + "\x99\x7f\x33\x25\xa5\xdf\xba\x77\x2b\xd3\x3e\xc2\x7b\x8b\x94\x07" | ||
597 | + "\xe9\x52\x5b\x43\x87\x34\x14\x86\x37\xcf\x41\x6b\x8e\x6a\xa5\x22" | ||
598 | + "\xab\xdb\x96\xa2\xcf\x46\xd8\x9b\x45\x93\xef\xd6\xdf\x3e\x99\x9c" | ||
599 | + "\x7e\x29\x10\x6b\x6c\xa2\xb8\x43\x05\x09\x44\x70\x8c\xb8\xaa\x54" | ||
600 | + "\x7c\x30\x36\x5e\x1c\x5e\x5b\x9f\x6c\x0d\x81\xee\xa0\x93\x8d\x67" | ||
601 | + "\x55\xf3\x87\xaf\xaa\x6b\x58\xf9\xbe\xb2\x36\x07\x42\x6e\xbd\x96" | ||
602 | + "\xe3\x9f\x1f\x8f\xc9\xf4\x9d\xae\x6a\x7d\x4c\x96\xbe\x5f\xc7\xcd" | ||
603 | + "\xf3\xb2\xf7\xcd\xf0\xcf\xc3\xe4\xf8\xfe\x37\x4f\x1c\x4d\xf6\x40" | ||
604 | + "\xf1\x6b\x7c\x4e\xe0\xa6\x71\xad\x56\xa7\x1c\x5c\x15\x6b\xfc\xf3" | ||
605 | + "\x01\x5d\xac\xf1\x75\x9a\x72\x6b\xaa\x28\xc5\x88\x6d\xfb\x33\x85" | ||
606 | + "\xe0\x4e\x61\xab\xeb\x31\x2c\x71\x08\x73\x11\x3b\xfc\xb5\xc0\x96" | ||
607 | + "\xcc\x87\x24\x44\xb5\x9b\x9e\xb3\x71\xba\xe9\xed\xb1\x4e\xd7\x76" | ||
608 | + "\x6c\xd2\xb6\x05\xb7\x5a\xde\xeb\x34\x5b\x96\x16\xfb\x59\xa9\x5c" | ||
609 | + "\x4f\x55\xca\x8a\xac\x59\xb0\xe4\x54\x39\x25\xbc\x81\x37\x2a\x09" | ||
610 | + "\x5f\x9e\x3b\x6b\x7d\x1f\x69\xf3\x34\x85\x39\x84\xa7\x28\x0b\xd3" | ||
611 | + "\xfd\xfb\x4b\x7a\xea\xe7\xd2\x3c\xd3\xda\x15\x68\xbc\x73\xd3\x22" | ||
612 | + "\x6f\xd7\x72\x5b\x2b\x66\xee\xa8\x0d\x54\xe8\x5b\xf9\x92\x96\x92" | ||
613 | + "\x93\xea\x97\x4a\xc7\x43\x10\x46\x35\xc5\xc0\x60\x8a\xe4\xc1\xb5" | ||
614 | + "\x36\xc6\xae\xed\xf7\x70\xa5\x86\x99\x3d\x91\xf8\xfd\x4e\x53\xeb" | ||
615 | + "\xbb\xbd\x6d\xec\x8f\xd7\x89\x3d\x31\x7f\xd7\x78\xba\x50\xbb\x74" | ||
616 | + "\x9d\xf6\xac\x4e\xb9\x03\x9c\x79\xd5\xe1\xbd\x17\x68\xd9\x13\x0b" | ||
617 | + "\x45\x75\x88\x00\x1d\x1f\xae\x73\x6a\x1d\x5c\x6e\x44\x9f\xa6\xfa" | ||
618 | + "\x4e\xd8\x25\x8b\xc0\xbc\xb2\x99\xe3\x17\x24\xb3\x23\xe2\x48\x8b" | ||
619 | + "\xfa\x22\xe7\x7e\x8f\xe6\x3f\x5f\x55\x0d\x75\xd3\x51\x0b\xd7\xed" | ||
620 | + "\xd3\x6f\x97\x3b\x85\x42\x80\x7e\x5f\xdc\x1b\xd6\xba\xee\xc4\x80" | ||
621 | + "\xce\x06\xa9\x15\x8c\x97\x5f\x40\x69\xb2\x4d\xc5\xb2\x5c\x1e\x01" | ||
622 | + "\x87\x7e\xe0\x36\x6d\x78\x80\x4e\x3c\x02\xec\x90\x1d\x11\x81\x74" | ||
623 | + "\xa5\x8b\xa4\xa0\x56\x06\xd5\x79\x72\x85\x57\x3b\xb2\x2e\xae\x90" | ||
624 | + "\x18\x8d\x91\xb2\x0e\x44\x19\xaa\xb4\xcc\x08\xed\x46\xfa\xd7\x2b" | ||
625 | + "\x78\x58\x72\x5d\xbb\x5e\x49\xe7\xee\xf3\x8a\x9d\x22\xa4\x19\xc8" | ||
626 | + "\xe7\x08\xc3\x90\x9b\x35\x9a\xa4\x25\x8c\x4b\x9b\xa7\xf8\xbf\x81" | ||
627 | + "\xf5\xdf\x22\x66\xf1\x7e\x9f\x66\x3d\xbb\xfa\x73\x73\x4d\xfd\x67" | ||
628 | + "\x7b\xf4\xce\xc3\x62\x2e\x6f\xbb\x0c\xa2\xdc\x69\xfc\x8a\x17\x0e" | ||
629 | + "\x3a\x9e\x83\x46\xd7\xe3\x5e\x65\x86\xc0\x51\x00\xbb\x91\xe3\xe1" | ||
630 | + "\xc1\x16\xc4\xe9\x65\x5c\x14\x3e\x44\x6a\x6b\xd1\x1e\xb0\x36\xdd" | ||
631 | + "\x0b\x7d\x8a\xeb\xaf\x58\x5b\x64\x3f\x38\xed\x52\x76\xe8\x46\xf7" | ||
632 | + "\x86\x84\xb3\x93\xb1\x0b\xe5\xfd\xfd\x0d\xe9\x6d\xe4\xf1\x1b\x1d" | ||
633 | + "\x56\xb4\x34\xe4\x6a\xf5\xa4\x9c\x2c\xc9\x64\x94\xc1\xf5\x79\x6d" | ||
634 | + "\x12\x96\xf3\x47\xc5\x48\xa8\xdb\xd8\x95\x64\x29\xcf\xf6\x88\xf1" | ||
635 | + "\x95\x7a\x98\xe8\xbc\x27\x19\xce\x73\x61\xd1\xb8\xc6\x31\x8c\xe7" | ||
636 | + "\x39\xce\x77\x9e\xbc\xc6\x31\x8c\x63\xf3\x9c\xe7\x39\xc6\x31\x8f" | ||
637 | + "\xf7\xce\x7e\x1e\x3b\x7f\x0f\x0f\x0f\x13\x57\xb9\x0a\xe1\x0b\x64" | ||
638 | + "\x5f\x58\x40\xc6\xc7\x7a\x4b\xf2\x3d\xbc\x71\xf4\xa7\xd2\xca\x14" | ||
639 | + "\xe2\x98\x1a\x30\x1e\xe0\x26\x5a\x6a\xf0\x9c\x67\x38\x66\x00\xb8" | ||
640 | + "\x72\xe6\xbe\xac\xfe\x12\xd3\x0b\x56\x73\x8c\x63\xc7\x2b\xe1\xe2" | ||
641 | + "\xe8\xdd\x7b\xff\x00\xd8\xe5\x23\x6c\xce\xa8\x69\xcf\x5e\x3a\xef" | ||
642 | + "\x77\xea\xe5\xab\x0e\x82\xdb\xd9\xed\x7a\x9e\xb8\x6d\x51\x32\xdb" | ||
643 | + "\x79\xc3\x36\x9a\x2d\xa3\x50\x39\x65\x0a\x63\x0e\xe5\xd4\x39\x12" | ||
644 | + "\xbf\x8b\x98\xa4\xa1\x2d\xad\xb3\xcf\x65\x6a\x43\x78\xb3\x3b\x07" | ||
645 | + "\xd8\xd5\xea\xae\x76\xad\x6f\xf5\xff\x00\xca\x93\xab\x96\xb0\x64" | ||
646 | + "\xeb\xd6\x4a\xd5\x87\xba\xec\x24\x60\x97\x06\x76\x03\xe3\x4c\x07" | ||
647 | + "\x29\x11\x8e\x34\x25\x02\x64\x29\xf0\x25\x48\x85\x3a\x33\x8b\x7a" | ||
648 | + "\x3c\x86\x1e\x75\xa5\x61\xc6\x97\x9f\x8d\x25\xf5\xc9\xcd\xde\xc9" | ||
649 | + "\x7d\x77\xf2\xc8\x7e\x70\xaf\x73\x5f\x2d\xec\xa2\x51\x2d\x96\xfb" | ||
650 | + "\x89\xad\x80\x57\xb2\x36\x1d\x7d\x83\x45\xac\xf3\xdb\xcc\x6c\x31" | ||
651 | + "\x4f\xcf\x30\x58\xd0\x12\x28\x90\x50\x42\x86\xfb\x48\x16\x3c\xc5" | ||
652 | + "\x9c\xf8\xe7\xcc\x29\x88\xb3\x4a\x4b\x4e\x6c\xbc\xdb\xc7\xbb\xe9" | ||
653 | + "\xb6\xa0\x8b\x11\xa1\x7d\x73\xd7\xe9\xbf\x7e\xc2\x6c\x10\x8d\xee" | ||
654 | + "\x9d\xef\x63\x3a\xe0\xf5\xbe\x8c\x3e\xa1\xc7\xc5\xd1\x00\x44\x1e" | ||
655 | + "\xf3\x51\xf2\xe2\xb0\xe3\xb5\x13\x7f\x32\xf1\x8c\xa6\x22\xfe\x1f" | ||
656 | + "\x49\x4d\xbb\xcf\x3a\x5d\xed\x4c\xd2\xfc\x85\xed\x23\xd6\xc7\x50" | ||
657 | + "\xb6\x5b\x3a\x16\x83\xb8\x6f\xfd\x32\x3f\xaa\x36\x34\xbb\xf5\x96" | ||
658 | + "\xa9\xab\xcf\x9f\x8f\xac\xc3\xca\xd5\x8b\xd8\x48\x9e\x79\xaa\x30" | ||
659 | + "\x87\xca\x58\x4d\x59\x96\xb9\x4f\xc5\x1b\x1c\xd2\xda\x5b\xe6\x57" | ||
660 | + "\x29\xa1\x28\x7a\x2b\x5b\xff\x00\x12\x2f\x5e\x3f\xf3\xbb\x8e\x7f" | ||
661 | + "\xec\xc6\x98\xff\x00\xed\x3c\xa6\xdd\xa9\xdc\x7e\xa0\xf7\xd6\x99" | ||
662 | + "\x31\xa2\xf7\xaf\x6b\xe9\x82\x74\x4b\x3d\x8f\x5e\x58\x0b\x33\xab" | ||
663 | + "\xef\xc3\xaf\x84\x64\xb9\xae\xb6\x25\x5f\x62\x8f\x1c\xe3\xf4\x51" | ||
664 | + "\xb7\x96\xe3\x0e\x30\x42\xa9\x18\x39\xbf\x9e\x2a\x1f\x74\x19\x02" | ||
665 | + "\x2d\x43\x93\x06\x63\xb1\xa7\x47\x6a\xfa\x9b\x6c\xeb\xbd\xe9\xae" | ||
666 | + "\x6a\x7b\x6f\x53\x5a\x60\x5d\xb5\xcd\xe8\x67\xeb\x35\x3b\x48\xc6" | ||
667 | + "\xa6\xb3\x04\xc8\xdf\xb8\x7e\x26\x64\xb0\xc9\x18\xb0\xa7\x33\xf2" | ||
668 | + "\x4a\x8b\x22\x3b\x8d\x4b\x89\x1d\xf6\x9d\x65\xc4\x38\xd2\x54\x9c" | ||
669 | + "\xe3\xcd\x89\xe1\xe1\xe6\x3e\x70\x81\x45\x1d\x18\xf9\x31\x83\xc8" | ||
670 | + "\xbe\x14\x82\x4b\x87\x7a\x74\x28\xd2\xdd\x12\x55\x30\xe6\x0e\x49" | ||
671 | + "\x31\x8e\x48\x69\xc5\xc0\x20\x91\xe4\x48\x41\x4c\xd8\xb9\x6a\x4e" | ||
672 | + "\x21\xce\x99\x1b\x0e\xfd\x09\x4f\xa1\x79\x0f\x0f\x0f\x0f\x0f\x0f" | ||
673 | + "\x0f\x3f\x3c\xb8\x71\x27\xc7\x72\x24\xe8\xb1\xa6\xc5\x7b\x18\xc3" | ||
674 | + "\xb1\xa5\xb0\xd4\x98\xee\xe3\x19\xc6\x71\x87\x19\x79\x2b\x6d\x78" | ||
675 | + "\xc6\x71\x8c\xe3\x0a\x4e\x71\x8c\xe3\x19\xfe\x38\xf2\x3b\xfb\x8b" | ||
676 | + "\x48\xfe\x4e\xaa\xff\x00\x4f\x08\xff\x00\xc7\xe1\xfb\x8b\x48\xfe" | ||
677 | + "\x4e\xaa\xff\x00\x4f\x08\xff\x00\xc7\xe4\x95\x86\x18\x8a\xcb\x31" | ||
678 | + "\xa3\x32\xd4\x78\xf1\xdb\x43\x2c\x47\x61\xb4\x32\xcb\x2c\xb4\x9c" | ||
679 | + "\x21\xb6\x99\x69\xbc\x25\xb6\xdb\x6d\x18\xc2\x10\xda\x12\x94\xa1" | ||
680 | + "\x38\xc2\x53\x8c\x63\x18\xc7\x9d\xbe\x7f\xff\xd9" | ||
681 | + ; | ||
682 | diff -Naur php-5.2.4/main/suhosin_patch.c php-5.2.4-suhosin/main/suhosin_patch.c | ||
683 | --- php-5.2.4/main/suhosin_patch.c 1970-01-01 01:00:00.000000000 +0100 | ||
684 | +++ php-5.2.4-suhosin/main/suhosin_patch.c 2007-09-07 20:11:39.000000000 +0200 | ||
685 | @@ -0,0 +1,380 @@ | ||
686 | +/* | ||
687 | + +----------------------------------------------------------------------+ | ||
688 | + | Suhosin Patch for PHP | | ||
689 | + +----------------------------------------------------------------------+ | ||
690 | + | Copyright (c) 2004-2006 Stefan Esser | | ||
691 | + +----------------------------------------------------------------------+ | ||
692 | + | This source file is subject to version 2.02 of the PHP license, | | ||
693 | + | that is bundled with this package in the file LICENSE, and is | | ||
694 | + | available at through the world-wide-web at | | ||
695 | + | http://www.php.net/license/2_02.txt. | | ||
696 | + | If you did not receive a copy of the PHP license and are unable to | | ||
697 | + | obtain it through the world-wide-web, please send a note to | | ||
698 | + | license@php.net so we can mail you a copy immediately. | | ||
699 | + +----------------------------------------------------------------------+ | ||
700 | + | Author: Stefan Esser <sesser@hardened-php.net> | | ||
701 | + +----------------------------------------------------------------------+ | ||
702 | + */ | ||
703 | +/* $Id: php5-5.2.4-suhosin-0.9.6.2.patch,v 1.1 2007-09-07 18:27:59 niro Exp $ */ | ||
704 | + | ||
705 | +#include "php.h" | ||
706 | + | ||
707 | +#include <stdio.h> | ||
708 | +#include <stdlib.h> | ||
709 | + | ||
710 | +#if HAVE_UNISTD_H | ||
711 | +#include <unistd.h> | ||
712 | +#endif | ||
713 | +#include "SAPI.h" | ||
714 | +#include "php_globals.h" | ||
715 | + | ||
716 | +#if SUHOSIN_PATCH | ||
717 | + | ||
718 | +#ifdef HAVE_SYS_SOCKET_H | ||
719 | +#include <sys/socket.h> | ||
720 | +#endif | ||
721 | + | ||
722 | +#if defined(PHP_WIN32) || defined(__riscos__) || defined(NETWARE) | ||
723 | +#undef AF_UNIX | ||
724 | +#endif | ||
725 | + | ||
726 | +#if defined(AF_UNIX) | ||
727 | +#include <sys/un.h> | ||
728 | +#endif | ||
729 | + | ||
730 | +#define SYSLOG_PATH "/dev/log" | ||
731 | + | ||
732 | +#ifdef PHP_WIN32 | ||
733 | +static HANDLE log_source = 0; | ||
734 | +#endif | ||
735 | + | ||
736 | +#include "snprintf.h" | ||
737 | + | ||
738 | +#include "suhosin_patch.h" | ||
739 | + | ||
740 | +#ifdef ZTS | ||
741 | +#include "suhosin_globals.h" | ||
742 | +int suhosin_patch_globals_id; | ||
743 | +#else | ||
744 | +struct _suhosin_patch_globals suhosin_patch_globals; | ||
745 | +#endif | ||
746 | + | ||
747 | +static void php_security_log(int loglevel, char *fmt, ...); | ||
748 | + | ||
749 | +static void suhosin_patch_globals_ctor(suhosin_patch_globals_struct *suhosin_patch_globals TSRMLS_DC) | ||
750 | +{ | ||
751 | + memset(suhosin_patch_globals, 0, sizeof(*suhosin_patch_globals)); | ||
752 | +} | ||
753 | + | ||
754 | +PHPAPI void suhosin_startup() | ||
755 | +{ | ||
756 | +#ifdef ZTS | ||
757 | + ts_allocate_id(&suhosin_patch_globals_id, sizeof(suhosin_patch_globals_struct), (ts_allocate_ctor) suhosin_patch_globals_ctor, NULL); | ||
758 | +#else | ||
759 | + suhosin_patch_globals_ctor(&suhosin_patch_globals TSRMLS_CC); | ||
760 | +#endif | ||
761 | + zend_suhosin_log = php_security_log; | ||
762 | +} | ||
763 | + | ||
764 | +/*PHPAPI void suhosin_clear_mm_canaries(TSRMLS_D) | ||
765 | +{ | ||
766 | + zend_alloc_clear_mm_canaries(AG(heap)); | ||
767 | + SPG(canary_1) = zend_canary(); | ||
768 | + SPG(canary_2) = zend_canary(); | ||
769 | + SPG(canary_3) = zend_canary(); | ||
770 | +}*/ | ||
771 | + | ||
772 | +static char *loglevel2string(int loglevel) | ||
773 | +{ | ||
774 | + switch (loglevel) { | ||
775 | + case S_FILES: | ||
776 | + return "FILES"; | ||
777 | + case S_INCLUDE: | ||
778 | + return "INCLUDE"; | ||
779 | + case S_MEMORY: | ||
780 | + return "MEMORY"; | ||
781 | + case S_MISC: | ||
782 | + return "MISC"; | ||
783 | + case S_SESSION: | ||
784 | + return "SESSION"; | ||
785 | + case S_SQL: | ||
786 | + return "SQL"; | ||
787 | + case S_EXECUTOR: | ||
788 | + return "EXECUTOR"; | ||
789 | + case S_VARS: | ||
790 | + return "VARS"; | ||
791 | + default: | ||
792 | + return "UNKNOWN"; | ||
793 | + } | ||
794 | +} | ||
795 | + | ||
796 | +static void php_security_log(int loglevel, char *fmt, ...) | ||
797 | +{ | ||
798 | + int s, r, i=0; | ||
799 | +#if defined(AF_UNIX) | ||
800 | + struct sockaddr_un saun; | ||
801 | +#endif | ||
802 | +#ifdef PHP_WIN32 | ||
803 | + LPTSTR strs[2]; | ||
804 | + unsigned short etype; | ||
805 | + DWORD evid; | ||
806 | +#endif | ||
807 | + char buf[4096+64]; | ||
808 | + char error[4096+100]; | ||
809 | + char *ip_address; | ||
810 | + char *fname; | ||
811 | + char *alertstring; | ||
812 | + int lineno; | ||
813 | + va_list ap; | ||
814 | + TSRMLS_FETCH(); | ||
815 | + | ||
816 | + /*SDEBUG("(suhosin_log) loglevel: %d log_syslog: %u - log_sapi: %u - log_script: %u", loglevel, SPG(log_syslog), SPG(log_sapi), SPG(log_script));*/ | ||
817 | + | ||
818 | + if (SPG(log_use_x_forwarded_for)) { | ||
819 | + ip_address = sapi_getenv("HTTP_X_FORWARDED_FOR", 20 TSRMLS_CC); | ||
820 | + if (ip_address == NULL) { | ||
821 | + ip_address = "X-FORWARDED-FOR not set"; | ||
822 | + } | ||
823 | + } else { | ||
824 | + ip_address = sapi_getenv("REMOTE_ADDR", 11 TSRMLS_CC); | ||
825 | + if (ip_address == NULL) { | ||
826 | + ip_address = "REMOTE_ADDR not set"; | ||
827 | + } | ||
828 | + } | ||
829 | + | ||
830 | + | ||
831 | + va_start(ap, fmt); | ||
832 | + ap_php_vsnprintf(error, sizeof(error), fmt, ap); | ||
833 | + va_end(ap); | ||
834 | + while (error[i]) { | ||
835 | + if (error[i] < 32) error[i] = '.'; | ||
836 | + i++; | ||
837 | + } | ||
838 | + | ||
839 | +/* if (SPG(simulation)) { | ||
840 | + alertstring = "ALERT-SIMULATION"; | ||
841 | + } else { */ | ||
842 | + alertstring = "ALERT"; | ||
843 | +/* }*/ | ||
844 | + | ||
845 | + if (zend_is_executing(TSRMLS_C)) { | ||
846 | + if (EG(current_execute_data)) { | ||
847 | + lineno = EG(current_execute_data)->opline->lineno; | ||
848 | + fname = EG(current_execute_data)->op_array->filename; | ||
849 | + } else { | ||
850 | + lineno = zend_get_executed_lineno(TSRMLS_C); | ||
851 | + fname = zend_get_executed_filename(TSRMLS_C); | ||
852 | + } | ||
853 | + ap_php_snprintf(buf, sizeof(buf), "%s - %s (attacker '%s', file '%s', line %u)", alertstring, error, ip_address, fname, lineno); | ||
854 | + } else { | ||
855 | + fname = sapi_getenv("SCRIPT_FILENAME", 15 TSRMLS_CC); | ||
856 | + if (fname==NULL) { | ||
857 | + fname = "unknown"; | ||
858 | + } | ||
859 | + ap_php_snprintf(buf, sizeof(buf), "%s - %s (attacker '%s', file '%s')", alertstring, error, ip_address, fname); | ||
860 | + } | ||
861 | + | ||
862 | + /* Syslog-Logging disabled? */ | ||
863 | + if (((SPG(log_syslog)|S_INTERNAL) & loglevel)==0) { | ||
864 | + goto log_sapi; | ||
865 | + } | ||
866 | + | ||
867 | +#if defined(AF_UNIX) | ||
868 | + ap_php_snprintf(error, sizeof(error), "<%u>suhosin[%u]: %s\n", (unsigned int)(SPG(log_syslog_facility)|SPG(log_syslog_priority)),getpid(),buf); | ||
869 | + | ||
870 | + s = socket(AF_UNIX, SOCK_DGRAM, 0); | ||
871 | + if (s == -1) { | ||
872 | + goto log_sapi; | ||
873 | + } | ||
874 | + | ||
875 | + memset(&saun, 0, sizeof(saun)); | ||
876 | + saun.sun_family = AF_UNIX; | ||
877 | + strcpy(saun.sun_path, SYSLOG_PATH); | ||
878 | + /*saun.sun_len = sizeof(saun);*/ | ||
879 | + | ||
880 | + r = connect(s, (struct sockaddr *)&saun, sizeof(saun)); | ||
881 | + if (r) { | ||
882 | + close(s); | ||
883 | + s = socket(AF_UNIX, SOCK_STREAM, 0); | ||
884 | + if (s == -1) { | ||
885 | + goto log_sapi; | ||
886 | + } | ||
887 | + | ||
888 | + memset(&saun, 0, sizeof(saun)); | ||
889 | + saun.sun_family = AF_UNIX; | ||
890 | + strcpy(saun.sun_path, SYSLOG_PATH); | ||
891 | + /*saun.sun_len = sizeof(saun);*/ | ||
892 | + | ||
893 | + r = connect(s, (struct sockaddr *)&saun, sizeof(saun)); | ||
894 | + if (r) { | ||
895 | + close(s); | ||
896 | + goto log_sapi; | ||
897 | + } | ||
898 | + } | ||
899 | + send(s, error, strlen(error), 0); | ||
900 | + | ||
901 | + close(s); | ||
902 | +#endif | ||
903 | +#ifdef PHP_WIN32 | ||
904 | + ap_php_snprintf(error, sizeof(error), "suhosin[%u]: %s", getpid(),buf); | ||
905 | + | ||
906 | + switch (SPG(log_syslog_priority)) { /* translate UNIX type into NT type */ | ||
907 | + case 1: /*LOG_ALERT:*/ | ||
908 | + etype = EVENTLOG_ERROR_TYPE; | ||
909 | + break; | ||
910 | + case 6: /*LOG_INFO:*/ | ||
911 | + etype = EVENTLOG_INFORMATION_TYPE; | ||
912 | + break; | ||
913 | + default: | ||
914 | + etype = EVENTLOG_WARNING_TYPE; | ||
915 | + } | ||
916 | + evid = loglevel; | ||
917 | + strs[0] = error; | ||
918 | + /* report the event */ | ||
919 | + if (log_source == NULL) { | ||
920 | + log_source = RegisterEventSource(NULL, "Suhosin-Patch-" SUHOSIN_PATCH_VERSION); | ||
921 | + } | ||
922 | + ReportEvent(log_source, etype, (unsigned short) SPG(log_syslog_priority), evid, NULL, 1, 0, strs, NULL); | ||
923 | + | ||
924 | +#endif | ||
925 | +log_sapi: | ||
926 | + /* SAPI Logging activated? */ | ||
927 | + /*SDEBUG("(suhosin_log) log_syslog: %u - log_sapi: %u - log_script: %u - log_phpscript: %u", SPG(log_syslog), SPG(log_sapi), SPG(log_script), SPG(log_phpscript));*/ | ||
928 | + if (((SPG(log_sapi)|S_INTERNAL) & loglevel)!=0) { | ||
929 | + sapi_module.log_message(buf); | ||
930 | + } | ||
931 | + | ||
932 | +/*log_script:*/ | ||
933 | + /* script logging activaed? */ | ||
934 | + if (((SPG(log_script) & loglevel)!=0) && SPG(log_scriptname)!=NULL) { | ||
935 | + char cmd[8192], *cmdpos, *bufpos; | ||
936 | + FILE *in; | ||
937 | + int space; | ||
938 | + | ||
939 | + ap_php_snprintf(cmd, sizeof(cmd), "%s %s \'", SPG(log_scriptname), loglevel2string(loglevel)); | ||
940 | + space = sizeof(cmd) - strlen(cmd); | ||
941 | + cmdpos = cmd + strlen(cmd); | ||
942 | + bufpos = buf; | ||
943 | + if (space <= 1) return; | ||
944 | + while (space > 2 && *bufpos) { | ||
945 | + if (*bufpos == '\'') { | ||
946 | + if (space<=5) break; | ||
947 | + *cmdpos++ = '\''; | ||
948 | + *cmdpos++ = '\\'; | ||
949 | + *cmdpos++ = '\''; | ||
950 | + *cmdpos++ = '\''; | ||
951 | + bufpos++; | ||
952 | + space-=4; | ||
953 | + } else { | ||
954 | + *cmdpos++ = *bufpos++; | ||
955 | + space--; | ||
956 | + } | ||
957 | + } | ||
958 | + *cmdpos++ = '\''; | ||
959 | + *cmdpos = 0; | ||
960 | + | ||
961 | + if ((in=VCWD_POPEN(cmd, "r"))==NULL) { | ||
962 | + php_security_log(S_INTERNAL, "Unable to execute logging shell script: %s", SPG(log_scriptname)); | ||
963 | + return; | ||
964 | + } | ||
965 | + /* read and forget the result */ | ||
966 | + while (1) { | ||
967 | + int readbytes = fread(cmd, 1, sizeof(cmd), in); | ||
968 | + if (readbytes<=0) { | ||
969 | + break; | ||
970 | + } | ||
971 | + } | ||
972 | + pclose(in); | ||
973 | + } | ||
974 | +/*log_phpscript:*/ | ||
975 | + if ((SPG(log_phpscript) & loglevel)!=0 && EG(in_execution) && SPG(log_phpscriptname) && SPG(log_phpscriptname)[0]) { | ||
976 | + zend_file_handle file_handle; | ||
977 | + zend_op_array *new_op_array; | ||
978 | + zval *result = NULL; | ||
979 | + | ||
980 | + /*long orig_execution_depth = SPG(execution_depth);*/ | ||
981 | + zend_bool orig_safe_mode = PG(safe_mode); | ||
982 | + char *orig_basedir = PG(open_basedir); | ||
983 | + | ||
984 | + char *phpscript = SPG(log_phpscriptname); | ||
985 | +/*SDEBUG("scriptname %s", SPG(log_phpscriptname));`*/ | ||
986 | +#ifdef ZEND_ENGINE_2 | ||
987 | + if (zend_stream_open(phpscript, &file_handle TSRMLS_CC) == SUCCESS) { | ||
988 | +#else | ||
989 | + if (zend_open(phpscript, &file_handle) == SUCCESS && ZEND_IS_VALID_FILE_HANDLE(&file_handle)) { | ||
990 | + file_handle.filename = phpscript; | ||
991 | + file_handle.free_filename = 0; | ||
992 | +#endif | ||
993 | + if (!file_handle.opened_path) { | ||
994 | + file_handle.opened_path = estrndup(phpscript, strlen(phpscript)); | ||
995 | + } | ||
996 | + new_op_array = zend_compile_file(&file_handle, ZEND_REQUIRE TSRMLS_CC); | ||
997 | + zend_destroy_file_handle(&file_handle TSRMLS_CC); | ||
998 | + if (new_op_array) { | ||
999 | + HashTable *active_symbol_table = EG(active_symbol_table); | ||
1000 | + zval *zerror, *zerror_class; | ||
1001 | + | ||
1002 | + if (active_symbol_table == NULL) { | ||
1003 | + active_symbol_table = &EG(symbol_table); | ||
1004 | + } | ||
1005 | + EG(return_value_ptr_ptr) = &result; | ||
1006 | + EG(active_op_array) = new_op_array; | ||
1007 | + | ||
1008 | + MAKE_STD_ZVAL(zerror); | ||
1009 | + MAKE_STD_ZVAL(zerror_class); | ||
1010 | + ZVAL_STRING(zerror, buf, 1); | ||
1011 | + ZVAL_LONG(zerror_class, loglevel); | ||
1012 | + | ||
1013 | + zend_hash_update(active_symbol_table, "SUHOSIN_ERROR", sizeof("SUHOSIN_ERROR"), (void **)&zerror, sizeof(zval *), NULL); | ||
1014 | + zend_hash_update(active_symbol_table, "SUHOSIN_ERRORCLASS", sizeof("SUHOSIN_ERRORCLASS"), (void **)&zerror_class, sizeof(zval *), NULL); | ||
1015 | + | ||
1016 | + /*SPG(execution_depth) = 0;*/ | ||
1017 | + if (SPG(log_phpscript_is_safe)) { | ||
1018 | + PG(safe_mode) = 0; | ||
1019 | + PG(open_basedir) = NULL; | ||
1020 | + } | ||
1021 | + | ||
1022 | + zend_execute(new_op_array TSRMLS_CC); | ||
1023 | + | ||
1024 | + /*SPG(execution_depth) = orig_execution_depth;*/ | ||
1025 | + PG(safe_mode) = orig_safe_mode; | ||
1026 | + PG(open_basedir) = orig_basedir; | ||
1027 | + | ||
1028 | +#ifdef ZEND_ENGINE_2 | ||
1029 | + destroy_op_array(new_op_array TSRMLS_CC); | ||
1030 | +#else | ||
1031 | + destroy_op_array(new_op_array); | ||
1032 | +#endif | ||
1033 | + efree(new_op_array); | ||
1034 | +#ifdef ZEND_ENGINE_2 | ||
1035 | + if (!EG(exception)) | ||
1036 | +#endif | ||
1037 | + { | ||
1038 | + if (EG(return_value_ptr_ptr)) { | ||
1039 | + zval_ptr_dtor(EG(return_value_ptr_ptr)); | ||
1040 | + EG(return_value_ptr_ptr) = NULL; | ||
1041 | + } | ||
1042 | + } | ||
1043 | + } else { | ||
1044 | + php_security_log(S_INTERNAL, "Unable to execute logging PHP script: %s", SPG(log_phpscriptname)); | ||
1045 | + return; | ||
1046 | + } | ||
1047 | + } else { | ||
1048 | + php_security_log(S_INTERNAL, "Unable to execute logging PHP script: %s", SPG(log_phpscriptname)); | ||
1049 | + return; | ||
1050 | + } | ||
1051 | + } | ||
1052 | + | ||
1053 | +} | ||
1054 | + | ||
1055 | + | ||
1056 | +#endif | ||
1057 | + | ||
1058 | +/* | ||
1059 | + * Local variables: | ||
1060 | + * tab-width: 4 | ||
1061 | + * c-basic-offset: 4 | ||
1062 | + * End: | ||
1063 | + * vim600: sw=4 ts=4 fdm=marker | ||
1064 | + * vim<600: sw=4 ts=4 | ||
1065 | + */ | ||
1066 | diff -Naur php-5.2.4/main/suhosin_patch.h php-5.2.4-suhosin/main/suhosin_patch.h | ||
1067 | --- php-5.2.4/main/suhosin_patch.h 1970-01-01 01:00:00.000000000 +0100 | ||
1068 | +++ php-5.2.4-suhosin/main/suhosin_patch.h 2007-09-07 20:11:39.000000000 +0200 | ||
1069 | @@ -0,0 +1,40 @@ | ||
1070 | +/* | ||
1071 | + +----------------------------------------------------------------------+ | ||
1072 | + | Suhosin Patch for PHP | | ||
1073 | + +----------------------------------------------------------------------+ | ||
1074 | + | Copyright (c) 2004-2006 Stefan Esser | | ||
1075 | + +----------------------------------------------------------------------+ | ||
1076 | + | This source file is subject to version 2.02 of the PHP license, | | ||
1077 | + | that is bundled with this package in the file LICENSE, and is | | ||
1078 | + | available at through the world-wide-web at | | ||
1079 | + | http://www.php.net/license/2_02.txt. | | ||
1080 | + | If you did not receive a copy of the PHP license and are unable to | | ||
1081 | + | obtain it through the world-wide-web, please send a note to | | ||
1082 | + | license@php.net so we can mail you a copy immediately. | | ||
1083 | + +----------------------------------------------------------------------+ | ||
1084 | + | Author: Stefan Esser <sesser@hardened-php.net> | | ||
1085 | + +----------------------------------------------------------------------+ | ||
1086 | + */ | ||
1087 | + | ||
1088 | +#ifndef SUHOSIN_PATCH_H | ||
1089 | +#define SUHOSIN_PATCH_H | ||
1090 | + | ||
1091 | +#if SUHOSIN_PATCH | ||
1092 | + | ||
1093 | +#include "zend.h" | ||
1094 | + | ||
1095 | +PHPAPI void suhosin_startup(); | ||
1096 | +#define SUHOSIN_PATCH_VERSION "0.9.6.2" | ||
1097 | + | ||
1098 | +#define SUHOSIN_LOGO_GUID "SUHO8567F54-D428-14d2-A769-00DA302A5F18" | ||
1099 | + | ||
1100 | +#endif | ||
1101 | + | ||
1102 | +#endif /* SUHOSIN_PATCH_H */ | ||
1103 | + | ||
1104 | +/* | ||
1105 | + * Local variables: | ||
1106 | + * tab-width: 4 | ||
1107 | + * c-basic-offset: 4 | ||
1108 | + * End: | ||
1109 | + */ | ||
1110 | diff -Naur php-5.2.4/main/suhosin_patch.m4 php-5.2.4-suhosin/main/suhosin_patch.m4 | ||
1111 | --- php-5.2.4/main/suhosin_patch.m4 1970-01-01 01:00:00.000000000 +0100 | ||
1112 | +++ php-5.2.4-suhosin/main/suhosin_patch.m4 2007-09-07 20:11:39.000000000 +0200 | ||
1113 | @@ -0,0 +1,8 @@ | ||
1114 | +dnl | ||
1115 | +dnl $Id: php5-5.2.4-suhosin-0.9.6.2.patch,v 1.1 2007-09-07 18:27:59 niro Exp $ | ||
1116 | +dnl | ||
1117 | +dnl This file contains Suhosin Patch for PHP specific autoconf functions. | ||
1118 | +dnl | ||
1119 | + | ||
1120 | +AC_DEFINE(SUHOSIN_PATCH, 1, [Suhosin Patch]) | ||
1121 | + | ||
1122 | diff -Naur php-5.2.4/sapi/apache/mod_php5.c php-5.2.4-suhosin/sapi/apache/mod_php5.c | ||
1123 | --- php-5.2.4/sapi/apache/mod_php5.c 2007-08-06 14:54:57.000000000 +0200 | ||
1124 | +++ php-5.2.4-suhosin/sapi/apache/mod_php5.c 2007-09-07 20:11:39.000000000 +0200 | ||
1125 | @@ -951,7 +951,11 @@ | ||
1126 | { | ||
1127 | TSRMLS_FETCH(); | ||
1128 | if (PG(expose_php)) { | ||
1129 | +#if SUHOSIN_PATCH | ||
1130 | + ap_add_version_component("PHP/" PHP_VERSION " with Suhosin-Patch"); | ||
1131 | +#else | ||
1132 | ap_add_version_component("PHP/" PHP_VERSION); | ||
1133 | +#endif | ||
1134 | } | ||
1135 | } | ||
1136 | #endif | ||
1137 | diff -Naur php-5.2.4/sapi/apache2filter/sapi_apache2.c php-5.2.4-suhosin/sapi/apache2filter/sapi_apache2.c | ||
1138 | --- php-5.2.4/sapi/apache2filter/sapi_apache2.c 2007-01-01 10:36:12.000000000 +0100 | ||
1139 | +++ php-5.2.4-suhosin/sapi/apache2filter/sapi_apache2.c 2007-09-07 20:11:39.000000000 +0200 | ||
1140 | @@ -562,7 +562,11 @@ | ||
1141 | { | ||
1142 | TSRMLS_FETCH(); | ||
1143 | if (PG(expose_php)) { | ||
1144 | +#if SUHOSIN_PATCH | ||
1145 | + ap_add_version_component(p, "PHP/" PHP_VERSION " with Suhosin-Patch"); | ||
1146 | +#else | ||
1147 | ap_add_version_component(p, "PHP/" PHP_VERSION); | ||
1148 | +#endif | ||
1149 | } | ||
1150 | } | ||
1151 | |||
1152 | diff -Naur php-5.2.4/sapi/apache2handler/sapi_apache2.c php-5.2.4-suhosin/sapi/apache2handler/sapi_apache2.c | ||
1153 | --- php-5.2.4/sapi/apache2handler/sapi_apache2.c 2007-06-28 19:23:07.000000000 +0200 | ||
1154 | +++ php-5.2.4-suhosin/sapi/apache2handler/sapi_apache2.c 2007-09-07 20:11:39.000000000 +0200 | ||
1155 | @@ -372,7 +372,11 @@ | ||
1156 | { | ||
1157 | TSRMLS_FETCH(); | ||
1158 | if (PG(expose_php)) { | ||
1159 | +#if SUHOSIN_PATCH | ||
1160 | + ap_add_version_component(p, "PHP/" PHP_VERSION " with Suhosin-Patch"); | ||
1161 | +#else | ||
1162 | ap_add_version_component(p, "PHP/" PHP_VERSION); | ||
1163 | +#endif | ||
1164 | } | ||
1165 | } | ||
1166 | |||
1167 | diff -Naur php-5.2.4/sapi/cgi/cgi_main.c php-5.2.4-suhosin/sapi/cgi/cgi_main.c | ||
1168 | --- php-5.2.4/sapi/cgi/cgi_main.c 2007-08-09 01:51:57.000000000 +0200 | ||
1169 | +++ php-5.2.4-suhosin/sapi/cgi/cgi_main.c 2007-09-07 20:11:39.000000000 +0200 | ||
1170 | @@ -1595,11 +1595,19 @@ | ||
1171 | SG(headers_sent) = 1; | ||
1172 | SG(request_info).no_headers = 1; | ||
1173 | } | ||
1174 | +#if SUHOSIN_PATCH | ||
1175 | +#if ZEND_DEBUG | ||
1176 | + php_printf("PHP %s with Suhosin-Patch %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, SUHOSIN_PATCH_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); | ||
1177 | +#else | ||
1178 | + php_printf("PHP %s with Suhosin-Patch %s (%s) (built: %s %s)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, SUHOSIN_PATCH_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); | ||
1179 | +#endif | ||
1180 | +#else | ||
1181 | #if ZEND_DEBUG | ||
1182 | php_printf("PHP %s (%s) (built: %s %s) (DEBUG)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); | ||
1183 | #else | ||
1184 | php_printf("PHP %s (%s) (built: %s %s)\nCopyright (c) 1997-2007 The PHP Group\n%s", PHP_VERSION, sapi_module.name, __DATE__, __TIME__, get_zend_version()); | ||
1185 | #endif | ||
1186 | +#endif | ||
1187 | php_end_ob_buffers(1 TSRMLS_CC); | ||
1188 | exit(0); | ||
1189 | break; | ||
1190 | diff -Naur php-5.2.4/sapi/cli/php_cli.c php-5.2.4-suhosin/sapi/cli/php_cli.c | ||
1191 | --- php-5.2.4/sapi/cli/php_cli.c 2007-08-09 01:51:24.000000000 +0200 | ||
1192 | +++ php-5.2.4-suhosin/sapi/cli/php_cli.c 2007-09-07 20:11:39.000000000 +0200 | ||
1193 | @@ -779,8 +779,14 @@ | ||
1194 | } | ||
1195 | |||
1196 | request_started = 1; | ||
1197 | - php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2007 The PHP Group\n%s", | ||
1198 | - PHP_VERSION, sapi_module.name, __DATE__, __TIME__, | ||
1199 | +#if SUHOSIN_PATCH | ||
1200 | + php_printf("PHP %s with Suhosin-Patch %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2007 The PHP Group\n%s", | ||
1201 | + PHP_VERSION, SUHOSIN_PATCH_VERSION, | ||
1202 | +#else | ||
1203 | + php_printf("PHP %s (%s) (built: %s %s) %s\nCopyright (c) 1997-2007 The PHP Group\n%s", | ||
1204 | + PHP_VERSION, | ||
1205 | +#endif | ||
1206 | + sapi_module.name, __DATE__, __TIME__, | ||
1207 | #if ZEND_DEBUG && defined(HAVE_GCOV) | ||
1208 | "(DEBUG GCOV)", | ||
1209 | #elif ZEND_DEBUG | ||
1210 | diff -Naur php-5.2.4/TSRM/TSRM.h php-5.2.4-suhosin/TSRM/TSRM.h | ||
1211 | --- php-5.2.4/TSRM/TSRM.h 2007-04-17 08:26:32.000000000 +0200 | ||
1212 | +++ php-5.2.4-suhosin/TSRM/TSRM.h 2007-09-07 20:11:39.000000000 +0200 | ||
1213 | @@ -38,6 +38,13 @@ | ||
1214 | typedef unsigned long tsrm_uintptr_t; | ||
1215 | #endif | ||
1216 | |||
1217 | +#if SUHOSIN_PATCH | ||
1218 | +# if HAVE_REALPATH | ||
1219 | +# undef realpath | ||
1220 | +# define realpath php_realpath | ||
1221 | +# endif | ||
1222 | +#endif | ||
1223 | + | ||
1224 | /* Only compile multi-threading functions if we're in ZTS mode */ | ||
1225 | #ifdef ZTS | ||
1226 | |||
1227 | @@ -93,6 +100,7 @@ | ||
1228 | |||
1229 | #define THREAD_HASH_OF(thr,ts) (unsigned long)thr%(unsigned long)ts | ||
1230 | |||
1231 | + | ||
1232 | #ifdef __cplusplus | ||
1233 | extern "C" { | ||
1234 | #endif | ||
1235 | diff -Naur php-5.2.4/TSRM/tsrm_virtual_cwd.c php-5.2.4-suhosin/TSRM/tsrm_virtual_cwd.c | ||
1236 | --- php-5.2.4/TSRM/tsrm_virtual_cwd.c 2007-08-10 11:09:46.000000000 +0200 | ||
1237 | +++ php-5.2.4-suhosin/TSRM/tsrm_virtual_cwd.c 2007-09-07 20:25:01.000000000 +0200 | ||
1238 | @@ -273,6 +273,176 @@ | ||
1239 | } | ||
1240 | /* }}} */ | ||
1241 | |||
1242 | +#if SUHOSIN_PATCH | ||
1243 | +CWD_API char *php_realpath(const char *path, char *resolved) | ||
1244 | +{ | ||
1245 | + struct stat sb; | ||
1246 | + char *p, *q, *s; | ||
1247 | + size_t left_len, resolved_len; | ||
1248 | + unsigned symlinks; | ||
1249 | + int serrno, slen; | ||
1250 | + int is_dir = 1; | ||
1251 | + char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX]; | ||
1252 | + | ||
1253 | + serrno = errno; | ||
1254 | + symlinks = 0; | ||
1255 | + if (path[0] == '/') { | ||
1256 | + resolved[0] = '/'; | ||
1257 | + resolved[1] = '\0'; | ||
1258 | + if (path[1] == '\0') | ||
1259 | + return (resolved); | ||
1260 | + resolved_len = 1; | ||
1261 | + left_len = strlcpy(left, path + 1, sizeof(left)); | ||
1262 | + } else { | ||
1263 | + if (getcwd(resolved, PATH_MAX) == NULL) { | ||
1264 | + strlcpy(resolved, ".", PATH_MAX); | ||
1265 | + return (NULL); | ||
1266 | + } | ||
1267 | + resolved_len = strlen(resolved); | ||
1268 | + left_len = strlcpy(left, path, sizeof(left)); | ||
1269 | + } | ||
1270 | + if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) { | ||
1271 | + errno = ENAMETOOLONG; | ||
1272 | + return (NULL); | ||
1273 | + } | ||
1274 | + | ||
1275 | + /* | ||
1276 | + * Iterate over path components in `left'. | ||
1277 | + */ | ||
1278 | + while (left_len != 0) { | ||
1279 | + /* | ||
1280 | + * Extract the next path component and adjust `left' | ||
1281 | + * and its length. | ||
1282 | + */ | ||
1283 | + p = strchr(left, '/'); | ||
1284 | + s = p ? p : left + left_len; | ||
1285 | + if (s - left >= sizeof(next_token)) { | ||
1286 | + errno = ENAMETOOLONG; | ||
1287 | + return (NULL); | ||
1288 | + } | ||
1289 | + memcpy(next_token, left, s - left); | ||
1290 | + next_token[s - left] = '\0'; | ||
1291 | + left_len -= s - left; | ||
1292 | + if (p != NULL) | ||
1293 | + memmove(left, s + 1, left_len + 1); | ||
1294 | + if (resolved[resolved_len - 1] != '/') { | ||
1295 | + if (resolved_len + 1 >= PATH_MAX) { | ||
1296 | + errno = ENAMETOOLONG; | ||
1297 | + return (NULL); | ||
1298 | + } | ||
1299 | + resolved[resolved_len++] = '/'; | ||
1300 | + resolved[resolved_len] = '\0'; | ||
1301 | + } | ||
1302 | + if (next_token[0] == '\0') | ||
1303 | + continue; | ||
1304 | + else if (strcmp(next_token, ".") == 0) | ||
1305 | + continue; | ||
1306 | + else if (strcmp(next_token, "..") == 0) { | ||
1307 | + /* | ||
1308 | + * Strip the last path component except when we have | ||
1309 | + * single "/" | ||
1310 | + */ | ||
1311 | + if (!is_dir) { | ||
1312 | + errno = ENOENT; | ||
1313 | + return (NULL); | ||
1314 | + } | ||
1315 | + if (resolved_len > 1) { | ||
1316 | + resolved[resolved_len - 1] = '\0'; | ||
1317 | + q = strrchr(resolved, '/'); | ||
1318 | + *q = '\0'; | ||
1319 | + resolved_len = q - resolved; | ||
1320 | + } | ||
1321 | + continue; | ||
1322 | + } | ||
1323 | + | ||
1324 | + /* | ||
1325 | + * Append the next path component and lstat() it. If | ||
1326 | + * lstat() fails we still can return successfully if | ||
1327 | + * there are no more path components left. | ||
1328 | + */ | ||
1329 | + resolved_len = strlcat(resolved, next_token, PATH_MAX); | ||
1330 | + if (resolved_len >= PATH_MAX) { | ||
1331 | + errno = ENAMETOOLONG; | ||
1332 | + return (NULL); | ||
1333 | + } | ||
1334 | + if (lstat(resolved, &sb) != 0) { | ||
1335 | + if (errno == ENOENT) { | ||
1336 | + if (p == NULL) { | ||
1337 | + errno = serrno; | ||
1338 | + return (resolved); | ||
1339 | + } else if (strstr(left, "/.") == NULL && strstr(left, "./") == NULL) { | ||
1340 | + resolved_len = strlcat(resolved, "/", PATH_MAX); | ||
1341 | + resolved_len = strlcat(resolved, left, PATH_MAX); | ||
1342 | + if (resolved_len >= PATH_MAX) { | ||
1343 | + errno = ENAMETOOLONG; | ||
1344 | + return (NULL); | ||
1345 | + } | ||
1346 | + errno = serrno; | ||
1347 | + return (resolved); | ||
1348 | + } | ||
1349 | + } | ||
1350 | + return (NULL); | ||
1351 | + } | ||
1352 | + if (S_ISLNK(sb.st_mode)) { | ||
1353 | + if (symlinks++ > MAXSYMLINKS) { | ||
1354 | + errno = ELOOP; | ||
1355 | + return (NULL); | ||
1356 | + } | ||
1357 | + slen = readlink(resolved, symlink, sizeof(symlink) - 1); | ||
1358 | + if (slen < 0) | ||
1359 | + return (NULL); | ||
1360 | + symlink[slen] = '\0'; | ||
1361 | + if (symlink[0] == '/') { | ||
1362 | + resolved[1] = 0; | ||
1363 | + resolved_len = 1; | ||
1364 | + } else if (resolved_len > 1) { | ||
1365 | + /* Strip the last path component. */ | ||
1366 | + resolved[resolved_len - 1] = '\0'; | ||
1367 | + q = strrchr(resolved, '/'); | ||
1368 | + *q = '\0'; | ||
1369 | + resolved_len = q - resolved; | ||
1370 | + } | ||
1371 | + | ||
1372 | + /* | ||
1373 | + * If there are any path components left, then | ||
1374 | + * append them to symlink. The result is placed | ||
1375 | + * in `left'. | ||
1376 | + */ | ||
1377 | + if (p != NULL) { | ||
1378 | + if (symlink[slen - 1] != '/') { | ||
1379 | + if (slen + 1 >= sizeof(symlink)) { | ||
1380 | + errno = ENAMETOOLONG; | ||
1381 | + return (NULL); | ||
1382 | + } | ||
1383 | + symlink[slen] = '/'; | ||
1384 | + symlink[slen + 1] = 0; | ||
1385 | + } | ||
1386 | + left_len = strlcat(symlink, left, sizeof(left)); | ||
1387 | + if (left_len >= sizeof(left)) { | ||
1388 | + errno = ENAMETOOLONG; | ||
1389 | + return (NULL); | ||
1390 | + } | ||
1391 | + } | ||
1392 | + left_len = strlcpy(left, symlink, sizeof(left)); | ||
1393 | + } else { | ||
1394 | + if (S_ISDIR(sb.st_mode)) { | ||
1395 | + is_dir = 1; | ||
1396 | + } else { | ||
1397 | + is_dir = 0; | ||
1398 | + } | ||
1399 | + } | ||
1400 | + } | ||
1401 | + | ||
1402 | + /* | ||
1403 | + * Remove trailing slash except when the resolved pathname | ||
1404 | + * is a single "/". | ||
1405 | + */ | ||
1406 | + if (resolved_len > 1 && resolved[resolved_len - 1] == '/') | ||
1407 | + resolved[resolved_len - 1] = '\0'; | ||
1408 | + return (resolved); | ||
1409 | +} | ||
1410 | +#endif | ||
1411 | + | ||
1412 | CWD_API void virtual_cwd_startup(void) /* {{{ */ | ||
1413 | { | ||
1414 | char cwd[MAXPATHLEN]; | ||
1415 | diff -Naur php-5.2.4/TSRM/tsrm_virtual_cwd.h php-5.2.4-suhosin/TSRM/tsrm_virtual_cwd.h | ||
1416 | --- php-5.2.4/TSRM/tsrm_virtual_cwd.h 2007-01-22 10:31:46.000000000 +0100 | ||
1417 | +++ php-5.2.4-suhosin/TSRM/tsrm_virtual_cwd.h 2007-09-07 20:11:39.000000000 +0200 | ||
1418 | @@ -139,6 +139,22 @@ | ||
1419 | |||
1420 | typedef int (*verify_path_func)(const cwd_state *); | ||
1421 | |||
1422 | +#ifndef HAVE_STRLCPY | ||
1423 | +CWD_API size_t php_strlcpy(char *dst, const char *src, size_t siz); | ||
1424 | +#undef strlcpy | ||
1425 | +#define strlcpy php_strlcpy | ||
1426 | +#endif | ||
1427 | + | ||
1428 | +#ifndef HAVE_STRLCAT | ||
1429 | +CWD_API size_t php_strlcat(char *dst, const char *src, size_t siz); | ||
1430 | +#undef strlcat | ||
1431 | +#define strlcat php_strlcat | ||
1432 | +#endif | ||
1433 | + | ||
1434 | + | ||
1435 | +#if SUHOSIN_PATCH | ||
1436 | +CWD_API char *php_realpath(const char *path, char *resolved); | ||
1437 | +#endif | ||
1438 | CWD_API void virtual_cwd_startup(void); | ||
1439 | CWD_API void virtual_cwd_shutdown(void); | ||
1440 | CWD_API char *virtual_getcwd_ex(size_t *length TSRMLS_DC); | ||
1441 | diff -Naur php-5.2.4/win32/build/config.w32 php-5.2.4-suhosin/win32/build/config.w32 | ||
1442 | --- php-5.2.4/win32/build/config.w32 2007-04-18 11:38:59.000000000 +0200 | ||
1443 | +++ php-5.2.4-suhosin/win32/build/config.w32 2007-09-07 20:11:39.000000000 +0200 | ||
1444 | @@ -299,7 +299,7 @@ | ||
1445 | zend_sprintf.c zend_ini.c zend_qsort.c zend_multibyte.c zend_ts_hash.c \ | ||
1446 | zend_stream.c zend_iterators.c zend_interfaces.c zend_objects.c \ | ||
1447 | zend_object_handlers.c zend_objects_API.c \ | ||
1448 | - zend_default_classes.c zend_execute.c zend_strtod.c"); | ||
1449 | + zend_default_classes.c zend_execute.c zend_strtod.c zend_canary.c"); | ||
1450 | |||
1451 | ADD_SOURCES("main", "main.c snprintf.c spprintf.c safe_mode.c fopen_wrappers.c \ | ||
1452 | php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \ | ||
1453 | @@ -344,6 +344,8 @@ | ||
1454 | AC_DEFINE('HAVE_USLEEP', 1); | ||
1455 | AC_DEFINE('HAVE_STRCOLL', 1); | ||
1456 | |||
1457 | +AC_DEFINE('SUHOSIN_PATCH', 1); | ||
1458 | + | ||
1459 | /* For snapshot builders, where can we find the additional | ||
1460 | * files that make up the snapshot template? */ | ||
1461 | ARG_WITH("snapshot-template", "Path to snapshot builder template dir", "no"); | ||
1462 | diff -Naur php-5.2.4/Zend/Makefile.am php-5.2.4-suhosin/Zend/Makefile.am | ||
1463 | --- php-5.2.4/Zend/Makefile.am 2006-12-05 09:07:57.000000000 +0100 | ||
1464 | +++ php-5.2.4-suhosin/Zend/Makefile.am 2007-09-07 20:11:39.000000000 +0200 | ||
1465 | @@ -17,7 +17,7 @@ | ||
1466 | zend_objects_API.c zend_ts_hash.c zend_stream.c \ | ||
1467 | zend_default_classes.c \ | ||
1468 | zend_iterators.c zend_interfaces.c zend_exceptions.c \ | ||
1469 | - zend_strtod.c zend_multibyte.c | ||
1470 | + zend_strtod.c zend_multibyte.c zend_canary.c | ||
1471 | |||
1472 | libZend_la_LDFLAGS = | ||
1473 | libZend_la_LIBADD = @ZEND_EXTRA_LIBS@ | ||
1474 | diff -Naur php-5.2.4/Zend/zend_alloc.c php-5.2.4-suhosin/Zend/zend_alloc.c | ||
1475 | --- php-5.2.4/Zend/zend_alloc.c 2007-07-25 13:13:00.000000000 +0200 | ||
1476 | +++ php-5.2.4-suhosin/Zend/zend_alloc.c 2007-09-07 20:11:39.000000000 +0200 | ||
1477 | @@ -311,13 +311,26 @@ | ||
1478 | #define MEM_BLOCK_GUARD 0x2A8FCC84 | ||
1479 | #define MEM_BLOCK_LEAK 0x6C5E8F2D | ||
1480 | |||
1481 | +#if SUHOSIN_PATCH | ||
1482 | +# define CANARY_SIZE sizeof(size_t) | ||
1483 | +#else | ||
1484 | +# define CANARY_SIZE 0 | ||
1485 | +#endif | ||
1486 | + | ||
1487 | /* mm block type */ | ||
1488 | typedef struct _zend_mm_block_info { | ||
1489 | #if ZEND_MM_COOKIES | ||
1490 | size_t _cookie; | ||
1491 | #endif | ||
1492 | - size_t _size; | ||
1493 | - size_t _prev; | ||
1494 | +#if SUHOSIN_PATCH | ||
1495 | + size_t canary_1; | ||
1496 | +#endif | ||
1497 | + size_t _size; | ||
1498 | + size_t _prev; | ||
1499 | +#if SUHOSIN_PATCH | ||
1500 | + size_t size; | ||
1501 | + size_t canary_2; | ||
1502 | +#endif | ||
1503 | } zend_mm_block_info; | ||
1504 | |||
1505 | #if ZEND_DEBUG | ||
1506 | @@ -422,6 +435,9 @@ | ||
1507 | int miss; | ||
1508 | } cache_stat[ZEND_MM_NUM_BUCKETS+1]; | ||
1509 | #endif | ||
1510 | +#if SUHOSIN_PATCH | ||
1511 | + size_t canary_1,canary_2,canary_3; | ||
1512 | +#endif | ||
1513 | }; | ||
1514 | |||
1515 | #define ZEND_MM_SMALL_FREE_BUCKET(heap, index) \ | ||
1516 | @@ -511,15 +527,15 @@ | ||
1517 | #define ZEND_MM_ALIGNED_SIZE(size) ((size + ZEND_MM_ALIGNMENT - 1) & ZEND_MM_ALIGNMENT_MASK) | ||
1518 | #define ZEND_MM_ALIGNED_HEADER_SIZE ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_block)) | ||
1519 | #define ZEND_MM_ALIGNED_FREE_HEADER_SIZE ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_small_free_block)) | ||
1520 | -#define ZEND_MM_MIN_ALLOC_BLOCK_SIZE ZEND_MM_ALIGNED_SIZE(ZEND_MM_ALIGNED_HEADER_SIZE + END_MAGIC_SIZE) | ||
1521 | +#define ZEND_MM_MIN_ALLOC_BLOCK_SIZE ZEND_MM_ALIGNED_SIZE(ZEND_MM_ALIGNED_HEADER_SIZE + END_MAGIC_SIZE + CANARY_SIZE) | ||
1522 | #define ZEND_MM_ALIGNED_MIN_HEADER_SIZE (ZEND_MM_MIN_ALLOC_BLOCK_SIZE>ZEND_MM_ALIGNED_FREE_HEADER_SIZE?ZEND_MM_MIN_ALLOC_BLOCK_SIZE:ZEND_MM_ALIGNED_FREE_HEADER_SIZE) | ||
1523 | #define ZEND_MM_ALIGNED_SEGMENT_SIZE ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_segment)) | ||
1524 | |||
1525 | -#define ZEND_MM_MIN_SIZE ((ZEND_MM_ALIGNED_MIN_HEADER_SIZE>(ZEND_MM_ALIGNED_HEADER_SIZE+END_MAGIC_SIZE))?(ZEND_MM_ALIGNED_MIN_HEADER_SIZE-(ZEND_MM_ALIGNED_HEADER_SIZE+END_MAGIC_SIZE)):0) | ||
1526 | +#define ZEND_MM_MIN_SIZE ((ZEND_MM_ALIGNED_MIN_HEADER_SIZE>(ZEND_MM_ALIGNED_HEADER_SIZE+END_MAGIC_SIZE+CANARY_SIZE))?(ZEND_MM_ALIGNED_MIN_HEADER_SIZE-(ZEND_MM_ALIGNED_HEADER_SIZE+END_MAGIC_SIZE+CANARY_SIZE)):0) | ||
1527 | |||
1528 | #define ZEND_MM_MAX_SMALL_SIZE ((ZEND_MM_NUM_BUCKETS<<ZEND_MM_ALIGNMENT_LOG2)+ZEND_MM_ALIGNED_MIN_HEADER_SIZE) | ||
1529 | |||
1530 | -#define ZEND_MM_TRUE_SIZE(size) ((size<ZEND_MM_MIN_SIZE)?(ZEND_MM_ALIGNED_MIN_HEADER_SIZE):(ZEND_MM_ALIGNED_SIZE(size+ZEND_MM_ALIGNED_HEADER_SIZE+END_MAGIC_SIZE))) | ||
1531 | +#define ZEND_MM_TRUE_SIZE(size) ((size<ZEND_MM_MIN_SIZE)?(ZEND_MM_ALIGNED_MIN_HEADER_SIZE):(ZEND_MM_ALIGNED_SIZE(size+ZEND_MM_ALIGNED_HEADER_SIZE+END_MAGIC_SIZE+CANARY_SIZE))) | ||
1532 | |||
1533 | #define ZEND_MM_BUCKET_INDEX(true_size) ((true_size>>ZEND_MM_ALIGNMENT_LOG2)-(ZEND_MM_ALIGNED_MIN_HEADER_SIZE>>ZEND_MM_ALIGNMENT_LOG2)) | ||
1534 | |||
1535 | @@ -581,6 +597,48 @@ | ||
1536 | |||
1537 | #endif | ||
1538 | |||
1539 | +#if SUHOSIN_PATCH | ||
1540 | + | ||
1541 | +# define SUHOSIN_MM_CHECK_CANARIES(block, MFUNCTION) do { \ | ||
1542 | + size_t *p = SUHOSIN_MM_END_CANARY_PTR(block), check; \ | ||
1543 | + if (((block)->info.canary_1 != heap->canary_1) || ((block)->info.canary_2 != heap->canary_2)) { \ | ||
1544 | + canary_mismatch: \ | ||
1545 | + zend_suhosin_log(S_MEMORY, "canary mismatch on " MFUNCTION " - heap overflow detected"); \ | ||
1546 | + exit(1); \ | ||
1547 | + } \ | ||
1548 | + memcpy(&check, p, CANARY_SIZE); \ | ||
1549 | + if (check != heap->canary_3) { \ | ||
1550 | + zend_suhosin_log(S_MEMORY, "canary mismatch on " MFUNCTION " - heap overflow detected"); \ | ||
1551 | + exit(1); \ | ||
1552 | + goto canary_mismatch; \ | ||
1553 | + } \ | ||
1554 | + } while (0) | ||
1555 | + | ||
1556 | +# define SUHOSIN_MM_SET_CANARIES(block) do { \ | ||
1557 | + (block)->info.canary_1 = heap->canary_1; \ | ||
1558 | + (block)->info.canary_2 = heap->canary_2; \ | ||
1559 | + } while (0) | ||
1560 | + | ||
1561 | +# define SUHOSIN_MM_END_CANARY_PTR(block) \ | ||
1562 | + (size_t*)(((char*)(ZEND_MM_DATA_OF(block))) + ((zend_mm_block*)(block))->info.size + END_MAGIC_SIZE) | ||
1563 | + | ||
1564 | +# define SUHOSIN_MM_SET_END_CANARY(block) do { \ | ||
1565 | + size_t *p = SUHOSIN_MM_END_CANARY_PTR(block); \ | ||
1566 | + memcpy(p, &heap->canary_3, CANARY_SIZE); \ | ||
1567 | + } while (0) | ||
1568 | + | ||
1569 | +#else | ||
1570 | + | ||
1571 | +# define SUHOSIN_MM_CHECK_CANARIES(block) | ||
1572 | + | ||
1573 | +# define SUHOSIN_MM_SET_CANARIES(block) | ||
1574 | + | ||
1575 | +# define SUHOSIN_MM_END_CANARY_PTR(block) | ||
1576 | + | ||
1577 | +# define SUHOSIN_MM_SET_END_CANARY(block) | ||
1578 | + | ||
1579 | +#endif | ||
1580 | + | ||
1581 | |||
1582 | #if ZEND_MM_HEAP_PROTECTION | ||
1583 | |||
1584 | @@ -779,6 +837,12 @@ | ||
1585 | if (EXPECTED(prev == mm_block)) { | ||
1586 | zend_mm_free_block **rp, **cp; | ||
1587 | |||
1588 | +#if SUHOSIN_PATCH | ||
1589 | + if (next != mm_block) { | ||
1590 | + zend_suhosin_log(S_MEMORY, "heap corrupt on efree() - heap corruption detected"); | ||
1591 | + exit(1); | ||
1592 | + } | ||
1593 | +#endif | ||
1594 | #if ZEND_MM_SAFE_UNLINKING | ||
1595 | if (UNEXPECTED(next != mm_block)) { | ||
1596 | zend_mm_panic("zend_mm_heap corrupted"); | ||
1597 | @@ -817,6 +881,12 @@ | ||
1598 | } | ||
1599 | } else { | ||
1600 | |||
1601 | +#if SUHOSIN_PATCH | ||
1602 | + if (prev->next_free_block != mm_block || next->prev_free_block != mm_block) { | ||
1603 | + zend_suhosin_log(S_MEMORY, "linked list corrupt on efree() - heap corruption detected"); | ||
1604 | + exit(1); | ||
1605 | + } | ||
1606 | +#endif | ||
1607 | #if ZEND_MM_SAFE_UNLINKING | ||
1608 | if (UNEXPECTED(prev->next_free_block != mm_block) || UNEXPECTED(next->prev_free_block != mm_block)) { | ||
1609 | zend_mm_panic("zend_mm_heap corrupted"); | ||
1610 | @@ -864,6 +934,11 @@ | ||
1611 | heap->large_free_buckets[i] = NULL; | ||
1612 | } | ||
1613 | heap->rest_buckets[0] = heap->rest_buckets[1] = ZEND_MM_REST_BUCKET(heap); | ||
1614 | +#if SUHOSIN_PATCH | ||
1615 | + heap->canary_1 = zend_canary(); | ||
1616 | + heap->canary_2 = zend_canary(); | ||
1617 | + heap->canary_3 = zend_canary(); | ||
1618 | +#endif | ||
1619 | } | ||
1620 | |||
1621 | static void zend_mm_del_segment(zend_mm_heap *heap, zend_mm_segment *segment) | ||
1622 | @@ -1741,6 +1816,11 @@ | ||
1623 | best_fit = heap->cache[index]; | ||
1624 | heap->cache[index] = best_fit->prev_free_block; | ||
1625 | heap->cached -= true_size; | ||
1626 | +#if SUHOSIN_PATCH | ||
1627 | + SUHOSIN_MM_SET_CANARIES(best_fit); | ||
1628 | + ((zend_mm_block*)best_fit)->info.size = size; | ||
1629 | + SUHOSIN_MM_SET_END_CANARY(best_fit); | ||
1630 | +#endif | ||
1631 | ZEND_MM_CHECK_MAGIC(best_fit, MEM_BLOCK_CACHED); | ||
1632 | ZEND_MM_SET_DEBUG_INFO(best_fit, size, 1, 0); | ||
1633 | return ZEND_MM_DATA_OF(best_fit); | ||
1634 | @@ -1875,6 +1955,12 @@ | ||
1635 | |||
1636 | ZEND_MM_SET_DEBUG_INFO(best_fit, size, 1, 1); | ||
1637 | |||
1638 | +#if SUHOSIN_PATCH | ||
1639 | + SUHOSIN_MM_SET_CANARIES(best_fit); | ||
1640 | + ((zend_mm_block*)best_fit)->info.size = size; | ||
1641 | + SUHOSIN_MM_SET_END_CANARY(best_fit); | ||
1642 | +#endif | ||
1643 | + | ||
1644 | heap->size += true_size; | ||
1645 | if (heap->peak < heap->size) { | ||
1646 | heap->peak = heap->size; | ||
1647 | @@ -1898,6 +1984,9 @@ | ||
1648 | |||
1649 | mm_block = ZEND_MM_HEADER_OF(p); | ||
1650 | size = ZEND_MM_BLOCK_SIZE(mm_block); | ||
1651 | +#if SUHOSIN_PATCH | ||
1652 | + SUHOSIN_MM_CHECK_CANARIES(mm_block, "efree()"); | ||
1653 | +#endif | ||
1654 | ZEND_MM_CHECK_PROTECTION(mm_block); | ||
1655 | |||
1656 | #if ZEND_DEBUG || ZEND_MM_HEAP_PROTECTION | ||
1657 | @@ -1960,6 +2049,9 @@ | ||
1658 | mm_block = ZEND_MM_HEADER_OF(p); | ||
1659 | true_size = ZEND_MM_TRUE_SIZE(size); | ||
1660 | orig_size = ZEND_MM_BLOCK_SIZE(mm_block); | ||
1661 | +#if SUHOSIN_PATCH | ||
1662 | + SUHOSIN_MM_CHECK_CANARIES(mm_block, "erealloc()"); | ||
1663 | +#endif | ||
1664 | ZEND_MM_CHECK_PROTECTION(mm_block); | ||
1665 | |||
1666 | if (UNEXPECTED(true_size < size)) { | ||
1667 | @@ -1991,6 +2083,11 @@ | ||
1668 | HANDLE_UNBLOCK_INTERRUPTIONS(); | ||
1669 | } | ||
1670 | ZEND_MM_SET_DEBUG_INFO(mm_block, size, 0, 0); | ||
1671 | +#if SUHOSIN_PATCH | ||
1672 | + SUHOSIN_MM_SET_CANARIES(mm_block); | ||
1673 | + ((zend_mm_block*)mm_block)->info.size = size; | ||
1674 | + SUHOSIN_MM_SET_END_CANARY(mm_block); | ||
1675 | +#endif | ||
1676 | return p; | ||
1677 | } | ||
1678 | |||
1679 | @@ -2010,13 +2107,18 @@ | ||
1680 | heap->cache[index] = best_fit->prev_free_block; | ||
1681 | ZEND_MM_CHECK_MAGIC(best_fit, MEM_BLOCK_CACHED); | ||
1682 | ZEND_MM_SET_DEBUG_INFO(best_fit, size, 1, 0); | ||
1683 | +#if SUHOSIN_PATCH | ||
1684 | + SUHOSIN_MM_SET_CANARIES(best_fit); | ||
1685 | + ((zend_mm_block*)best_fit)->info.size = size; | ||
1686 | + SUHOSIN_MM_SET_END_CANARY(best_fit); | ||
1687 | +#endif | ||
1688 | |||
1689 | ptr = ZEND_MM_DATA_OF(best_fit); | ||
1690 | |||
1691 | #if ZEND_DEBUG || ZEND_MM_HEAP_PROTECTION | ||
1692 | memcpy(ptr, p, mm_block->debug.size); | ||
1693 | #else | ||
1694 | - memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE); | ||
1695 | + memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE - CANARY_SIZE); | ||
1696 | #endif | ||
1697 | |||
1698 | heap->cached -= true_size - orig_size; | ||
1699 | @@ -2074,6 +2176,11 @@ | ||
1700 | if (heap->peak < heap->size) { | ||
1701 | heap->peak = heap->size; | ||
1702 | } | ||
1703 | +#if SUHOSIN_PATCH | ||
1704 | + SUHOSIN_MM_SET_CANARIES(mm_block); | ||
1705 | + ((zend_mm_block*)mm_block)->info.size = size; | ||
1706 | + SUHOSIN_MM_SET_END_CANARY(mm_block); | ||
1707 | +#endif | ||
1708 | HANDLE_UNBLOCK_INTERRUPTIONS(); | ||
1709 | return p; | ||
1710 | } else if (ZEND_MM_IS_FIRST_BLOCK(mm_block) && | ||
1711 | @@ -2177,6 +2284,11 @@ | ||
1712 | } | ||
1713 | |||
1714 | HANDLE_UNBLOCK_INTERRUPTIONS(); | ||
1715 | +#if SUHOSIN_PATCH | ||
1716 | + SUHOSIN_MM_SET_CANARIES(mm_block); | ||
1717 | + ((zend_mm_block*)mm_block)->info.size = size; | ||
1718 | + SUHOSIN_MM_SET_END_CANARY(mm_block); | ||
1719 | +#endif | ||
1720 | return ZEND_MM_DATA_OF(mm_block); | ||
1721 | } | ||
1722 | |||
1723 | @@ -2184,7 +2296,7 @@ | ||
1724 | #if ZEND_DEBUG || ZEND_MM_HEAP_PROTECTION | ||
1725 | memcpy(ptr, p, mm_block->debug.size); | ||
1726 | #else | ||
1727 | - memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE); | ||
1728 | + memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE - CANARY_SIZE); | ||
1729 | #endif | ||
1730 | _zend_mm_free_int(heap, p ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); | ||
1731 | return ptr; | ||
1732 | @@ -2427,6 +2539,17 @@ | ||
1733 | zend_mm_shutdown(AG(mm_heap), full_shutdown, silent); | ||
1734 | } | ||
1735 | |||
1736 | +#if SUHOSIN_PATCH | ||
1737 | +ZEND_API void suhosin_clear_mm_canaries(TSRMLS_D) | ||
1738 | +{ | ||
1739 | +/* NOT HERE | ||
1740 | + | ||
1741 | + AG(mm_heap)->canary_1 = zend_canary(); | ||
1742 | + AG(mm_heap)->canary_2 = zend_canary(); | ||
1743 | + AG(mm_heap)->canary_3 = zend_canary(); */ | ||
1744 | +} | ||
1745 | +#endif | ||
1746 | + | ||
1747 | static void alloc_globals_ctor(zend_alloc_globals *alloc_globals TSRMLS_DC) | ||
1748 | { | ||
1749 | char *tmp; | ||
1750 | diff -Naur php-5.2.4/Zend/zend_alloc.h php-5.2.4-suhosin/Zend/zend_alloc.h | ||
1751 | --- php-5.2.4/Zend/zend_alloc.h 2007-03-20 07:46:48.000000000 +0100 | ||
1752 | +++ php-5.2.4-suhosin/Zend/zend_alloc.h 2007-09-07 20:11:39.000000000 +0200 | ||
1753 | @@ -128,6 +128,9 @@ | ||
1754 | |||
1755 | ZEND_API void start_memory_manager(TSRMLS_D); | ||
1756 | ZEND_API void shutdown_memory_manager(int silent, int full_shutdown TSRMLS_DC); | ||
1757 | +#if SUHOSIN_PATCH | ||
1758 | +ZEND_API void suhosin_clear_mm_canaries(TSRMLS_D); | ||
1759 | +#endif | ||
1760 | ZEND_API int is_zend_mm(TSRMLS_D); | ||
1761 | |||
1762 | #if ZEND_DEBUG | ||
1763 | diff -Naur php-5.2.4/Zend/zend.c php-5.2.4-suhosin/Zend/zend.c | ||
1764 | --- php-5.2.4/Zend/zend.c 2007-07-21 02:35:14.000000000 +0200 | ||
1765 | +++ php-5.2.4-suhosin/Zend/zend.c 2007-09-07 20:11:39.000000000 +0200 | ||
1766 | @@ -57,7 +57,9 @@ | ||
1767 | ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args); | ||
1768 | int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap); | ||
1769 | ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC); | ||
1770 | - | ||
1771 | +#if SUHOSIN_PATCH | ||
1772 | +ZEND_API void (*zend_suhosin_log)(int loglevel, char *fmt, ...); | ||
1773 | +#endif | ||
1774 | void (*zend_on_timeout)(int seconds TSRMLS_DC); | ||
1775 | |||
1776 | static void (*zend_message_dispatcher_p)(long message, void *data); | ||
1777 | @@ -74,9 +76,88 @@ | ||
1778 | return SUCCESS; | ||
1779 | } | ||
1780 | |||
1781 | +#if SUHOSIN_PATCH | ||
1782 | +static ZEND_INI_MH(OnUpdateSuhosin_log_syslog) | ||
1783 | +{ | ||
1784 | + if (!new_value) { | ||
1785 | + SPG(log_syslog) = S_ALL & ~S_SQL | S_MEMORY; | ||
1786 | + } else { | ||
1787 | + SPG(log_syslog) = atoi(new_value) | S_MEMORY; | ||
1788 | + } | ||
1789 | + return SUCCESS; | ||
1790 | +} | ||
1791 | +static ZEND_INI_MH(OnUpdateSuhosin_log_syslog_facility) | ||
1792 | +{ | ||
1793 | + if (!new_value) { | ||
1794 | + SPG(log_syslog_facility) = LOG_USER; | ||
1795 | + } else { | ||
1796 | + SPG(log_syslog_facility) = atoi(new_value); | ||
1797 | + } | ||
1798 | + return SUCCESS; | ||
1799 | +} | ||
1800 | +static ZEND_INI_MH(OnUpdateSuhosin_log_syslog_priority) | ||
1801 | +{ | ||
1802 | + if (!new_value) { | ||
1803 | + SPG(log_syslog_priority) = LOG_ALERT; | ||
1804 | + } else { | ||
1805 | + SPG(log_syslog_priority) = atoi(new_value); | ||
1806 | + } | ||
1807 | + return SUCCESS; | ||
1808 | +} | ||
1809 | +static ZEND_INI_MH(OnUpdateSuhosin_log_sapi) | ||
1810 | +{ | ||
1811 | + if (!new_value) { | ||
1812 | + SPG(log_sapi) = S_ALL & ~S_SQL; | ||
1813 | + } else { | ||
1814 | + SPG(log_sapi) = atoi(new_value); | ||
1815 | + } | ||
1816 | + return SUCCESS; | ||
1817 | +} | ||
1818 | +static ZEND_INI_MH(OnUpdateSuhosin_log_script) | ||
1819 | +{ | ||
1820 | + if (!new_value) { | ||
1821 | + SPG(log_script) = S_ALL & ~S_MEMORY; | ||
1822 | + } else { | ||
1823 | + SPG(log_script) = atoi(new_value) & (~S_MEMORY) & (~S_INTERNAL); | ||
1824 | + } | ||
1825 | + return SUCCESS; | ||
1826 | +} | ||
1827 | +static ZEND_INI_MH(OnUpdateSuhosin_log_scriptname) | ||
1828 | +{ | ||
1829 | + if (SPG(log_scriptname)) { | ||
1830 | + pefree(SPG(log_scriptname),1); | ||
1831 | + } | ||
1832 | + SPG(log_scriptname) = NULL; | ||
1833 | + if (new_value) { | ||
1834 | + SPG(log_scriptname) = pestrdup(new_value,1); | ||
1835 | + } | ||
1836 | + return SUCCESS; | ||
1837 | +} | ||
1838 | +static ZEND_INI_MH(OnUpdateSuhosin_log_phpscript) | ||
1839 | +{ | ||
1840 | + if (!new_value) { | ||
1841 | + SPG(log_phpscript) = S_ALL & ~S_MEMORY; | ||
1842 | + } else { | ||
1843 | + SPG(log_phpscript) = atoi(new_value) & (~S_MEMORY) & (~S_INTERNAL); | ||
1844 | + } | ||
1845 | + return SUCCESS; | ||
1846 | +} | ||
1847 | +#endif | ||
1848 | |||
1849 | ZEND_INI_BEGIN() | ||
1850 | ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting) | ||
1851 | +#if SUHOSIN_PATCH | ||
1852 | + ZEND_INI_ENTRY("suhosin.log.syslog", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_syslog) | ||
1853 | + ZEND_INI_ENTRY("suhosin.log.syslog.facility", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_syslog_facility) | ||
1854 | + ZEND_INI_ENTRY("suhosin.log.syslog.priority", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_syslog_priority) | ||
1855 | + ZEND_INI_ENTRY("suhosin.log.sapi", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_sapi) | ||
1856 | + ZEND_INI_ENTRY("suhosin.log.script", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_script) | ||
1857 | + ZEND_INI_ENTRY("suhosin.log.script.name", NULL, ZEND_INI_SYSTEM, OnUpdateSuhosin_log_scriptname) | ||
1858 | + STD_ZEND_INI_BOOLEAN("suhosin.log.use-x-forwarded-for", "0", ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateBool, log_use_x_forwarded_for, suhosin_patch_globals_struct, suhosin_patch_globals) | ||
1859 | + ZEND_INI_ENTRY("suhosin.log.phpscript", "0", ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_phpscript) | ||
1860 | + STD_ZEND_INI_ENTRY("suhosin.log.phpscript.name", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateString, log_phpscriptname, suhosin_patch_globals_struct, suhosin_patch_globals) | ||
1861 | + STD_ZEND_INI_BOOLEAN("suhosin.log.phpscript.is_safe", "0", ZEND_INI_SYSTEM, OnUpdateBool, log_phpscript_is_safe, suhosin_patch_globals_struct, suhosin_patch_globals) | ||
1862 | +#endif | ||
1863 | STD_ZEND_INI_BOOLEAN("zend.ze1_compatibility_mode", "0", ZEND_INI_ALL, OnUpdateBool, ze1_compatibility_mode, zend_executor_globals, executor_globals) | ||
1864 | #ifdef ZEND_MULTIBYTE | ||
1865 | STD_ZEND_INI_BOOLEAN("detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals) | ||
1866 | diff -Naur php-5.2.4/Zend/zend_canary.c php-5.2.4-suhosin/Zend/zend_canary.c | ||
1867 | --- php-5.2.4/Zend/zend_canary.c 1970-01-01 01:00:00.000000000 +0100 | ||
1868 | +++ php-5.2.4-suhosin/Zend/zend_canary.c 2007-09-07 20:11:39.000000000 +0200 | ||
1869 | @@ -0,0 +1,64 @@ | ||
1870 | +/* | ||
1871 | + +----------------------------------------------------------------------+ | ||
1872 | + | Suhosin-Patch for PHP | | ||
1873 | + +----------------------------------------------------------------------+ | ||
1874 | + | Copyright (c) 2004-2006 Stefan Esser | | ||
1875 | + +----------------------------------------------------------------------+ | ||
1876 | + | This source file is subject to version 2.02 of the PHP license, | | ||
1877 | + | that is bundled with this package in the file LICENSE, and is | | ||
1878 | + | available at through the world-wide-web at | | ||
1879 | + | http://www.php.net/license/2_02.txt. | | ||
1880 | + | If you did not receive a copy of the PHP license and are unable to | | ||
1881 | + | obtain it through the world-wide-web, please send a note to | | ||
1882 | + | license@php.net so we can mail you a copy immediately. | | ||
1883 | + +----------------------------------------------------------------------+ | ||
1884 | + | Author: Stefan Esser <sesser@hardened-php.net> | | ||
1885 | + +----------------------------------------------------------------------+ | ||
1886 | + */ | ||
1887 | +/* $Id: php5-5.2.4-suhosin-0.9.6.2.patch,v 1.1 2007-09-07 18:27:59 niro Exp $ */ | ||
1888 | + | ||
1889 | +#include "zend.h" | ||
1890 | + | ||
1891 | +#include <stdio.h> | ||
1892 | +#include <stdlib.h> | ||
1893 | + | ||
1894 | + | ||
1895 | +#if SUHOSIN_PATCH | ||
1896 | + | ||
1897 | +static size_t last_canary = 0x73625123; | ||
1898 | + | ||
1899 | +/* will be replaced later with more compatible method */ | ||
1900 | +ZEND_API size_t zend_canary() | ||
1901 | +{ | ||
1902 | + time_t t; | ||
1903 | + size_t canary; | ||
1904 | + int fd; | ||
1905 | + | ||
1906 | +#ifndef PHP_WIN32 | ||
1907 | + fd = open("/dev/urandom", 0); | ||
1908 | + if (fd != -1) { | ||
1909 | + int r = read(fd, &canary, sizeof(canary)); | ||
1910 | + close(fd); | ||
1911 | + if (r == sizeof(canary)) { | ||
1912 | + return (canary); | ||
1913 | + } | ||
1914 | + } | ||
1915 | +#endif | ||
1916 | + /* not good but we never want to do this */ | ||
1917 | + time(&t); | ||
1918 | + canary = *(unsigned int *)&t + getpid() << 16 + last_canary; | ||
1919 | + last_canary ^= (canary << 5) | (canary >> (32-5)); | ||
1920 | + return (canary); | ||
1921 | +} | ||
1922 | + | ||
1923 | +#endif | ||
1924 | + | ||
1925 | + | ||
1926 | +/* | ||
1927 | + * Local variables: | ||
1928 | + * tab-width: 4 | ||
1929 | + * c-basic-offset: 4 | ||
1930 | + * End: | ||
1931 | + * vim600: sw=4 ts=4 fdm=marker | ||
1932 | + * vim<600: sw=4 ts=4 | ||
1933 | + */ | ||
1934 | diff -Naur php-5.2.4/Zend/zend_compile.c php-5.2.4-suhosin/Zend/zend_compile.c | ||
1935 | --- php-5.2.4/Zend/zend_compile.c 2007-05-18 15:12:03.000000000 +0200 | ||
1936 | +++ php-5.2.4-suhosin/Zend/zend_compile.c 2007-09-07 20:11:39.000000000 +0200 | ||
1937 | @@ -54,7 +54,6 @@ | ||
1938 | property_info->name = zend_strndup(property_info->name, property_info->name_length); | ||
1939 | } | ||
1940 | |||
1941 | - | ||
1942 | static void zend_destroy_property_info(zend_property_info *property_info) | ||
1943 | { | ||
1944 | efree(property_info->name); | ||
1945 | @@ -68,6 +67,10 @@ | ||
1946 | { | ||
1947 | free(property_info->name); | ||
1948 | } | ||
1949 | +#if SUHOSIN_PATCH | ||
1950 | +void *suhosin_zend_destroy_property_info_internal = zend_destroy_property_info_internal; | ||
1951 | +void *suhosin_zend_destroy_property_info = zend_destroy_property_info; | ||
1952 | +#endif | ||
1953 | |||
1954 | static void build_runtime_defined_function_key(zval *result, char *name, int name_length TSRMLS_DC) | ||
1955 | { | ||
1956 | diff -Naur php-5.2.4/Zend/zend_compile.h php-5.2.4-suhosin/Zend/zend_compile.h | ||
1957 | --- php-5.2.4/Zend/zend_compile.h 2007-05-18 15:12:04.000000000 +0200 | ||
1958 | +++ php-5.2.4-suhosin/Zend/zend_compile.h 2007-09-07 20:11:39.000000000 +0200 | ||
1959 | @@ -564,6 +564,11 @@ | ||
1960 | |||
1961 | int zendlex(znode *zendlval TSRMLS_DC); | ||
1962 | |||
1963 | +#if SUHOSIN_PATCH | ||
1964 | +extern void *suhosin_zend_destroy_property_info_internal; | ||
1965 | +extern void *suhosin_zend_destroy_property_info; | ||
1966 | +#endif | ||
1967 | + | ||
1968 | /* BEGIN: OPCODES */ | ||
1969 | |||
1970 | #include "zend_vm_opcodes.h" | ||
1971 | @@ -686,6 +691,7 @@ | ||
1972 | |||
1973 | #define ZEND_RETURNS_FUNCTION 1<<0 | ||
1974 | |||
1975 | + | ||
1976 | END_EXTERN_C() | ||
1977 | |||
1978 | #define ZEND_CLONE_FUNC_NAME "__clone" | ||
1979 | diff -Naur php-5.2.4/Zend/zend_constants.c php-5.2.4-suhosin/Zend/zend_constants.c | ||
1980 | --- php-5.2.4/Zend/zend_constants.c 2007-07-27 18:29:11.000000000 +0200 | ||
1981 | +++ php-5.2.4-suhosin/Zend/zend_constants.c 2007-09-07 20:11:39.000000000 +0200 | ||
1982 | @@ -110,6 +110,75 @@ | ||
1983 | REGISTER_MAIN_LONG_CONSTANT("E_USER_NOTICE", E_USER_NOTICE, CONST_PERSISTENT | CONST_CS); | ||
1984 | |||
1985 | REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS); | ||
1986 | +#if SUHOSIN_PATCH | ||
1987 | + REGISTER_MAIN_LONG_CONSTANT("S_MEMORY", S_MEMORY, CONST_PERSISTENT | CONST_CS); | ||
1988 | + REGISTER_MAIN_LONG_CONSTANT("S_VARS", S_VARS, CONST_PERSISTENT | CONST_CS); | ||
1989 | + REGISTER_MAIN_LONG_CONSTANT("S_FILES", S_FILES, CONST_PERSISTENT | CONST_CS); | ||
1990 | + REGISTER_MAIN_LONG_CONSTANT("S_INCLUDE", S_INCLUDE, CONST_PERSISTENT | CONST_CS); | ||
1991 | + REGISTER_MAIN_LONG_CONSTANT("S_SQL", S_SQL, CONST_PERSISTENT | CONST_CS); | ||
1992 | + REGISTER_MAIN_LONG_CONSTANT("S_EXECUTOR", S_EXECUTOR, CONST_PERSISTENT | CONST_CS); | ||
1993 | + REGISTER_MAIN_LONG_CONSTANT("S_MAIL", S_MAIL, CONST_PERSISTENT | CONST_CS); | ||
1994 | + REGISTER_MAIN_LONG_CONSTANT("S_SESSION", S_SESSION, CONST_PERSISTENT | CONST_CS); | ||
1995 | + REGISTER_MAIN_LONG_CONSTANT("S_MISC", S_MISC, CONST_PERSISTENT | CONST_CS); | ||
1996 | + REGISTER_MAIN_LONG_CONSTANT("S_INTERNAL", S_INTERNAL, CONST_PERSISTENT | CONST_CS); | ||
1997 | + REGISTER_MAIN_LONG_CONSTANT("S_ALL", S_ALL, CONST_PERSISTENT | CONST_CS); | ||
1998 | + | ||
1999 | + /* error levels */ | ||
2000 | + REGISTER_MAIN_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */ | ||
2001 | + REGISTER_MAIN_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */ | ||
2002 | + REGISTER_MAIN_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_CS | CONST_PERSISTENT); /* critical conditions */ | ||
2003 | + REGISTER_MAIN_LONG_CONSTANT("LOG_ERR", LOG_ERR, CONST_CS | CONST_PERSISTENT); | ||
2004 | + REGISTER_MAIN_LONG_CONSTANT("LOG_WARNING", LOG_WARNING, CONST_CS | CONST_PERSISTENT); | ||
2005 | + REGISTER_MAIN_LONG_CONSTANT("LOG_NOTICE", LOG_NOTICE, CONST_CS | CONST_PERSISTENT); | ||
2006 | + REGISTER_MAIN_LONG_CONSTANT("LOG_INFO", LOG_INFO, CONST_CS | CONST_PERSISTENT); | ||
2007 | + REGISTER_MAIN_LONG_CONSTANT("LOG_DEBUG", LOG_DEBUG, CONST_CS | CONST_PERSISTENT); | ||
2008 | + /* facility: type of program logging the message */ | ||
2009 | + REGISTER_MAIN_LONG_CONSTANT("LOG_KERN", LOG_KERN, CONST_CS | CONST_PERSISTENT); | ||
2010 | + REGISTER_MAIN_LONG_CONSTANT("LOG_USER", LOG_USER, CONST_CS | CONST_PERSISTENT); /* generic user level */ | ||
2011 | + REGISTER_MAIN_LONG_CONSTANT("LOG_MAIL", LOG_MAIL, CONST_CS | CONST_PERSISTENT); /* log to email */ | ||
2012 | + REGISTER_MAIN_LONG_CONSTANT("LOG_DAEMON", LOG_DAEMON, CONST_CS | CONST_PERSISTENT); /* other system daemons */ | ||
2013 | + REGISTER_MAIN_LONG_CONSTANT("LOG_AUTH", LOG_AUTH, CONST_CS | CONST_PERSISTENT); | ||
2014 | + REGISTER_MAIN_LONG_CONSTANT("LOG_SYSLOG", LOG_SYSLOG, CONST_CS | CONST_PERSISTENT); | ||
2015 | + REGISTER_MAIN_LONG_CONSTANT("LOG_LPR", LOG_LPR, CONST_CS | CONST_PERSISTENT); | ||
2016 | +#ifdef LOG_NEWS | ||
2017 | + /* No LOG_NEWS on HP-UX */ | ||
2018 | + REGISTER_MAIN_LONG_CONSTANT("LOG_NEWS", LOG_NEWS, CONST_CS | CONST_PERSISTENT); /* usenet new */ | ||
2019 | +#endif | ||
2020 | +#ifdef LOG_UUCP | ||
2021 | + /* No LOG_UUCP on HP-UX */ | ||
2022 | + REGISTER_MAIN_LONG_CONSTANT("LOG_UUCP", LOG_UUCP, CONST_CS | CONST_PERSISTENT); | ||
2023 | +#endif | ||
2024 | +#ifdef LOG_CRON | ||
2025 | + /* apparently some systems don't have this one */ | ||
2026 | + REGISTER_MAIN_LONG_CONSTANT("LOG_CRON", LOG_CRON, CONST_CS | CONST_PERSISTENT); | ||
2027 | +#endif | ||
2028 | +#ifdef LOG_AUTHPRIV | ||
2029 | + /* AIX doesn't have LOG_AUTHPRIV */ | ||
2030 | + REGISTER_MAIN_LONG_CONSTANT("LOG_AUTHPRIV", LOG_AUTHPRIV, CONST_CS | CONST_PERSISTENT); | ||
2031 | +#endif | ||
2032 | +#if !defined(PHP_WIN32) && !defined(NETWARE) | ||
2033 | + REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL0", LOG_LOCAL0, CONST_CS | CONST_PERSISTENT); | ||
2034 | + REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL1", LOG_LOCAL1, CONST_CS | CONST_PERSISTENT); | ||
2035 | + REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL2", LOG_LOCAL2, CONST_CS | CONST_PERSISTENT); | ||
2036 | + REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL3", LOG_LOCAL3, CONST_CS | CONST_PERSISTENT); | ||
2037 | + REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL4", LOG_LOCAL4, CONST_CS | CONST_PERSISTENT); | ||
2038 | + REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL5", LOG_LOCAL5, CONST_CS | CONST_PERSISTENT); | ||
2039 | + REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL6", LOG_LOCAL6, CONST_CS | CONST_PERSISTENT); | ||
2040 | + REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL7", LOG_LOCAL7, CONST_CS | CONST_PERSISTENT); | ||
2041 | +#endif | ||
2042 | + /* options */ | ||
2043 | + REGISTER_MAIN_LONG_CONSTANT("LOG_PID", LOG_PID, CONST_CS | CONST_PERSISTENT); | ||
2044 | + REGISTER_MAIN_LONG_CONSTANT("LOG_CONS", LOG_CONS, CONST_CS | CONST_PERSISTENT); | ||
2045 | + REGISTER_MAIN_LONG_CONSTANT("LOG_ODELAY", LOG_ODELAY, CONST_CS | CONST_PERSISTENT); | ||
2046 | + REGISTER_MAIN_LONG_CONSTANT("LOG_NDELAY", LOG_NDELAY, CONST_CS | CONST_PERSISTENT); | ||
2047 | +#ifdef LOG_NOWAIT | ||
2048 | + REGISTER_MAIN_LONG_CONSTANT("LOG_NOWAIT", LOG_NOWAIT, CONST_CS | CONST_PERSISTENT); | ||
2049 | +#endif | ||
2050 | +#ifdef LOG_PERROR | ||
2051 | + /* AIX doesn't have LOG_PERROR */ | ||
2052 | + REGISTER_MAIN_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/ | ||
2053 | +#endif | ||
2054 | +#endif | ||
2055 | |||
2056 | /* true/false constants */ | ||
2057 | { | ||
2058 | diff -Naur php-5.2.4/Zend/Zend.dsp php-5.2.4-suhosin/Zend/Zend.dsp | ||
2059 | --- php-5.2.4/Zend/Zend.dsp 2006-12-05 09:07:57.000000000 +0100 | ||
2060 | +++ php-5.2.4-suhosin/Zend/Zend.dsp 2007-09-07 20:11:39.000000000 +0200 | ||
2061 | @@ -239,6 +239,10 @@ | ||
2062 | # End Source File | ||
2063 | # Begin Source File | ||
2064 | |||
2065 | +SOURCE=.\zend_canary.c | ||
2066 | +# End Source File | ||
2067 | +# Begin Source File | ||
2068 | + | ||
2069 | SOURCE=.\zend_ts_hash.c | ||
2070 | # End Source File | ||
2071 | # Begin Source File | ||
2072 | diff -Naur php-5.2.4/Zend/zend_errors.h php-5.2.4-suhosin/Zend/zend_errors.h | ||
2073 | --- php-5.2.4/Zend/zend_errors.h 2007-01-01 10:35:46.000000000 +0100 | ||
2074 | +++ php-5.2.4-suhosin/Zend/zend_errors.h 2007-09-07 20:11:39.000000000 +0200 | ||
2075 | @@ -39,6 +39,20 @@ | ||
2076 | #define E_ALL (E_ERROR | E_WARNING | E_PARSE | E_NOTICE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_RECOVERABLE_ERROR) | ||
2077 | #define E_CORE (E_CORE_ERROR | E_CORE_WARNING) | ||
2078 | |||
2079 | +#if SUHOSIN_PATCH | ||
2080 | +#define S_MEMORY (1<<0L) | ||
2081 | +#define S_MISC (1<<1L) | ||
2082 | +#define S_VARS (1<<2L) | ||
2083 | +#define S_FILES (1<<3L) | ||
2084 | +#define S_INCLUDE (1<<4L) | ||
2085 | +#define S_SQL (1<<5L) | ||
2086 | +#define S_EXECUTOR (1<<6L) | ||
2087 | +#define S_MAIL (1<<7L) | ||
2088 | +#define S_SESSION (1<<8L) | ||
2089 | +#define S_INTERNAL (1<<29L) | ||
2090 | +#define S_ALL (S_MEMORY | S_VARS | S_INCLUDE | S_FILES | S_MAIL | S_SESSION | S_MISC | S_SQL | S_EXECUTOR) | ||
2091 | +#endif | ||
2092 | + | ||
2093 | #endif /* ZEND_ERRORS_H */ | ||
2094 | |||
2095 | /* | ||
2096 | diff -Naur php-5.2.4/Zend/zend.h php-5.2.4-suhosin/Zend/zend.h | ||
2097 | --- php-5.2.4/Zend/zend.h 2007-07-23 18:17:10.000000000 +0200 | ||
2098 | +++ php-5.2.4-suhosin/Zend/zend.h 2007-09-07 20:11:39.000000000 +0200 | ||
2099 | @@ -520,6 +520,9 @@ | ||
2100 | extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC); | ||
2101 | extern int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap); | ||
2102 | extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC); | ||
2103 | +#if SUHOSIN_PATCH | ||
2104 | +extern ZEND_API void (*zend_suhosin_log)(int loglevel, char *fmt, ...); | ||
2105 | +#endif | ||
2106 | |||
2107 | |||
2108 | ZEND_API void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3); | ||
2109 | @@ -651,6 +654,13 @@ | ||
2110 | #include "zend_operators.h" | ||
2111 | #include "zend_variables.h" | ||
2112 | |||
2113 | +#if SUHOSIN_PATCH | ||
2114 | +#include "suhosin_globals.h" | ||
2115 | +#include "php_syslog.h" | ||
2116 | + | ||
2117 | +ZEND_API size_t zend_canary(); | ||
2118 | +#endif | ||
2119 | + | ||
2120 | #endif /* ZEND_H */ | ||
2121 | |||
2122 | /* | ||
2123 | diff -Naur php-5.2.4/Zend/zend_hash.c php-5.2.4-suhosin/Zend/zend_hash.c | ||
2124 | --- php-5.2.4/Zend/zend_hash.c 2007-07-24 20:28:39.000000000 +0200 | ||
2125 | +++ php-5.2.4-suhosin/Zend/zend_hash.c 2007-09-07 20:11:39.000000000 +0200 | ||
2126 | @@ -20,6 +20,7 @@ | ||
2127 | /* $Id: php5-5.2.4-suhosin-0.9.6.2.patch,v 1.1 2007-09-07 18:27:59 niro Exp $ */ | ||
2128 | |||
2129 | #include "zend.h" | ||
2130 | +#include "zend_compile.h" | ||
2131 | |||
2132 | #define CONNECT_TO_BUCKET_DLLIST(element, list_head) \ | ||
2133 | (element)->pNext = (list_head); \ | ||
2134 | @@ -132,7 +133,189 @@ | ||
2135 | (p)->pDataPtr=NULL; \ | ||
2136 | } | ||
2137 | |||
2138 | +#if SUHOSIN_PATCH | ||
2139 | +#ifdef ZTS | ||
2140 | +MUTEX_T zend_hash_dprot_mx_reader; | ||
2141 | +MUTEX_T zend_hash_dprot_mx_writer; | ||
2142 | +unsigned int zend_hash_dprot_reader; | ||
2143 | +#endif | ||
2144 | +unsigned int zend_hash_dprot_counter; | ||
2145 | +unsigned int zend_hash_dprot_curmax; | ||
2146 | +dtor_func_t *zend_hash_dprot_table = NULL; | ||
2147 | + | ||
2148 | +static void zend_hash_dprot_begin_read() | ||
2149 | +{ | ||
2150 | +#ifdef ZTS | ||
2151 | + tsrm_mutex_lock(zend_hash_dprot_mx_reader); | ||
2152 | + if ((++(zend_hash_dprot_reader)) == 1) { | ||
2153 | + tsrm_mutex_lock(zend_hash_dprot_mx_writer); | ||
2154 | + } | ||
2155 | + tsrm_mutex_unlock(zend_hash_dprot_mx_reader); | ||
2156 | +#endif | ||
2157 | +} | ||
2158 | + | ||
2159 | +static void zend_hash_dprot_end_read() | ||
2160 | +{ | ||
2161 | +#ifdef ZTS | ||
2162 | + tsrm_mutex_lock(zend_hash_dprot_mx_reader); | ||
2163 | + if ((--(zend_hash_dprot_reader)) == 0) { | ||
2164 | + tsrm_mutex_unlock(zend_hash_dprot_mx_writer); | ||
2165 | + } | ||
2166 | + tsrm_mutex_unlock(zend_hash_dprot_mx_reader); | ||
2167 | +#endif | ||
2168 | +} | ||
2169 | + | ||
2170 | +static void zend_hash_dprot_begin_write() | ||
2171 | +{ | ||
2172 | +#ifdef ZTS | ||
2173 | + tsrm_mutex_lock(zend_hash_dprot_mx_writer); | ||
2174 | +#endif | ||
2175 | +} | ||
2176 | + | ||
2177 | +static void zend_hash_dprot_end_write() | ||
2178 | +{ | ||
2179 | +#ifdef ZTS | ||
2180 | + tsrm_mutex_unlock(zend_hash_dprot_mx_writer); | ||
2181 | +#endif | ||
2182 | +} | ||
2183 | + | ||
2184 | +/*ZEND_API void zend_hash_dprot_dtor() | ||
2185 | +{ | ||
2186 | +#ifdef ZTS | ||
2187 | + tsrm_mutex_free(zend_hash_dprot_mx_reader); | ||
2188 | + tsrm_mutex_free(zend_hash_dprot_mx_writer); | ||
2189 | +#endif | ||
2190 | + free(zend_hash_dprot_table); | ||
2191 | +}*/ | ||
2192 | + | ||
2193 | +static void zend_hash_add_destructor(dtor_func_t pDestructor) | ||
2194 | +{ | ||
2195 | + int left, right, mid; | ||
2196 | + zend_bool found = 0; | ||
2197 | + unsigned long value; | ||
2198 | + | ||
2199 | + if (pDestructor == NULL || pDestructor == ZVAL_PTR_DTOR || pDestructor == ZVAL_INTERNAL_PTR_DTOR | ||
2200 | + || pDestructor == ZEND_FUNCTION_DTOR || pDestructor == ZEND_CLASS_DTOR) { | ||
2201 | + return; | ||
2202 | + } | ||
2203 | + | ||
2204 | + if (zend_hash_dprot_table == NULL) { | ||
2205 | +#ifdef ZTS | ||
2206 | + zend_hash_dprot_mx_reader = tsrm_mutex_alloc(); | ||
2207 | + zend_hash_dprot_mx_writer = tsrm_mutex_alloc(); | ||
2208 | + zend_hash_dprot_reader = 0; | ||
2209 | +#endif | ||
2210 | + zend_hash_dprot_counter = 0; | ||
2211 | + zend_hash_dprot_curmax = 256; | ||
2212 | + zend_hash_dprot_table = (dtor_func_t *) malloc(256 * sizeof(dtor_func_t)); | ||
2213 | + } | ||
2214 | + | ||
2215 | + zend_hash_dprot_begin_write(); | ||
2216 | + | ||
2217 | + if (zend_hash_dprot_counter == 0) { | ||
2218 | + zend_hash_dprot_counter++; | ||
2219 | + zend_hash_dprot_table[0] = pDestructor; | ||
2220 | + } else { | ||
2221 | + value = (unsigned long) pDestructor; | ||
2222 | + left = 0; | ||
2223 | + right = zend_hash_dprot_counter-1; | ||
2224 | + mid = 0; | ||
2225 | + | ||
2226 | + while (left < right) { | ||
2227 | + mid = (right - left) >> 1; | ||
2228 | + mid += left; | ||
2229 | + if ((unsigned long)zend_hash_dprot_table[mid] == value) { | ||
2230 | + found = 1; | ||
2231 | + break; | ||
2232 | + } | ||
2233 | + if (value < (unsigned long)zend_hash_dprot_table[mid]) { | ||
2234 | + right = mid-1; | ||
2235 | + } else { | ||
2236 | + left = mid+1; | ||
2237 | + } | ||
2238 | + } | ||
2239 | + if ((unsigned long)zend_hash_dprot_table[left] == value) { | ||
2240 | + found = 1; | ||
2241 | + } | ||
2242 | + | ||
2243 | + if (!found) { | ||
2244 | + | ||
2245 | + if (zend_hash_dprot_counter >= zend_hash_dprot_curmax) { | ||
2246 | + zend_hash_dprot_curmax += 256; | ||
2247 | + zend_hash_dprot_table = (dtor_func_t *) realloc(zend_hash_dprot_table, zend_hash_dprot_curmax * sizeof(dtor_func_t)); | ||
2248 | + } | ||
2249 | + | ||
2250 | + if ((unsigned long)zend_hash_dprot_table[left] < value) { | ||
2251 | + memmove(zend_hash_dprot_table+left+2, zend_hash_dprot_table+left+1, (zend_hash_dprot_counter-left-1)*sizeof(dtor_func_t)); | ||
2252 | + zend_hash_dprot_table[left+1] = pDestructor; | ||
2253 | + } else { | ||
2254 | + memmove(zend_hash_dprot_table+left+1, zend_hash_dprot_table+left, (zend_hash_dprot_counter-left)*sizeof(dtor_func_t)); | ||
2255 | + zend_hash_dprot_table[left] = pDestructor; | ||
2256 | + } | ||
2257 | + | ||
2258 | + zend_hash_dprot_counter++; | ||
2259 | + } | ||
2260 | + } | ||
2261 | + | ||
2262 | + zend_hash_dprot_end_write(); | ||
2263 | +} | ||
2264 | + | ||
2265 | +static void zend_hash_check_destructor(dtor_func_t pDestructor) | ||
2266 | +{ | ||
2267 | + unsigned long value; | ||
2268 | + | ||
2269 | + if (pDestructor == NULL || pDestructor == ZVAL_PTR_DTOR || pDestructor == ZVAL_INTERNAL_PTR_DTOR | ||
2270 | +#ifdef ZEND_ENGINE_2 | ||
2271 | + || pDestructor == suhosin_zend_destroy_property_info_internal || pDestructor == suhosin_zend_destroy_property_info | ||
2272 | +#endif | ||
2273 | + || pDestructor == ZEND_FUNCTION_DTOR || pDestructor == ZEND_CLASS_DTOR) { | ||
2274 | + return; | ||
2275 | + } | ||
2276 | + | ||
2277 | + zend_hash_dprot_begin_read(); | ||
2278 | + | ||
2279 | + if (zend_hash_dprot_counter > 0) { | ||
2280 | + int left, right, mid; | ||
2281 | + zend_bool found = 0; | ||
2282 | + | ||
2283 | + value = (unsigned long) pDestructor; | ||
2284 | + left = 0; | ||
2285 | + right = zend_hash_dprot_counter-1; | ||
2286 | + | ||
2287 | + while (left < right) { | ||
2288 | + mid = (right - left) >> 1; | ||
2289 | + mid += left; | ||
2290 | + if ((unsigned long)zend_hash_dprot_table[mid] == value) { | ||
2291 | + found = 1; | ||
2292 | + break; | ||
2293 | + } | ||
2294 | + if (value < (unsigned long)zend_hash_dprot_table[mid]) { | ||
2295 | + right = mid-1; | ||
2296 | + } else { | ||
2297 | + left = mid+1; | ||
2298 | + } | ||
2299 | + } | ||
2300 | + if ((unsigned long)zend_hash_dprot_table[left] == value) { | ||
2301 | + found = 1; | ||
2302 | + } | ||
2303 | + | ||
2304 | + if (!found) { | ||
2305 | + zend_hash_dprot_end_read(); | ||
2306 | + | ||
2307 | + zend_suhosin_log(S_MEMORY, "possible memory corruption detected - unknown Hashtable destructor"); | ||
2308 | + exit(1); | ||
2309 | + return; | ||
2310 | + } | ||
2311 | + | ||
2312 | + } | ||
2313 | + | ||
2314 | + zend_hash_dprot_end_read(); | ||
2315 | +} | ||
2316 | |||
2317 | +#else | ||
2318 | +#define zend_hash_add_destructor(pDestructor) do {} while(0) | ||
2319 | +#define zend_hash_check_destructor(pDestructor) do {} while(0) | ||
2320 | +#endif | ||
2321 | |||
2322 | ZEND_API int _zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, zend_bool persistent ZEND_FILE_LINE_DC) | ||
2323 | { | ||
2324 | @@ -153,6 +336,7 @@ | ||
2325 | |||
2326 | ht->nTableMask = ht->nTableSize - 1; | ||
2327 | ht->pDestructor = pDestructor; | ||
2328 | + zend_hash_add_destructor(pDestructor); | ||
2329 | ht->arBuckets = NULL; | ||
2330 | ht->pListHead = NULL; | ||
2331 | ht->pListTail = NULL; | ||
2332 | @@ -230,6 +414,8 @@ | ||
2333 | return FAILURE; | ||
2334 | } | ||
2335 | #endif | ||
2336 | + | ||
2337 | + zend_hash_check_destructor(ht->pDestructor); | ||
2338 | if (ht->pDestructor) { | ||
2339 | ht->pDestructor(p->pData); | ||
2340 | } | ||
2341 | @@ -295,6 +481,7 @@ | ||
2342 | return FAILURE; | ||
2343 | } | ||
2344 | #endif | ||
2345 | + zend_hash_check_destructor(ht->pDestructor); | ||
2346 | if (ht->pDestructor) { | ||
2347 | ht->pDestructor(p->pData); | ||
2348 | } | ||
2349 | @@ -370,6 +557,7 @@ | ||
2350 | return FAILURE; | ||
2351 | } | ||
2352 | #endif | ||
2353 | + zend_hash_check_destructor(ht->pDestructor); | ||
2354 | if (ht->pDestructor) { | ||
2355 | ht->pDestructor(p->pData); | ||
2356 | } | ||
2357 | @@ -493,6 +681,7 @@ | ||
2358 | if (ht->pInternalPointer == p) { | ||
2359 | ht->pInternalPointer = p->pListNext; | ||
2360 | } | ||
2361 | + zend_hash_check_destructor(ht->pDestructor); | ||
2362 | if (ht->pDestructor) { | ||
2363 | ht->pDestructor(p->pData); | ||
2364 | } | ||
2365 | @@ -518,6 +707,8 @@ | ||
2366 | |||
2367 | SET_INCONSISTENT(HT_IS_DESTROYING); | ||
2368 | |||
2369 | + zend_hash_check_destructor(ht->pDestructor); | ||
2370 | + | ||
2371 | p = ht->pListHead; | ||
2372 | while (p != NULL) { | ||
2373 | q = p; | ||
2374 | @@ -544,6 +735,8 @@ | ||
2375 | |||
2376 | SET_INCONSISTENT(HT_CLEANING); | ||
2377 | |||
2378 | + zend_hash_check_destructor(ht->pDestructor); | ||
2379 | + | ||
2380 | p = ht->pListHead; | ||
2381 | while (p != NULL) { | ||
2382 | q = p; | ||
2383 | @@ -607,6 +800,7 @@ | ||
2384 | ht->nNumOfElements--; | ||
2385 | HANDLE_UNBLOCK_INTERRUPTIONS(); | ||
2386 | |||
2387 | + zend_hash_check_destructor(ht->pDestructor); | ||
2388 | if (ht->pDestructor) { | ||
2389 | ht->pDestructor(p->pData); | ||
2390 | } | ||
2391 | diff -Naur php-5.2.4/Zend/zend_llist.c php-5.2.4-suhosin/Zend/zend_llist.c | ||
2392 | --- php-5.2.4/Zend/zend_llist.c 2007-02-16 09:33:28.000000000 +0100 | ||
2393 | +++ php-5.2.4-suhosin/Zend/zend_llist.c 2007-09-07 20:11:39.000000000 +0200 | ||
2394 | @@ -23,6 +23,184 @@ | ||
2395 | #include "zend_llist.h" | ||
2396 | #include "zend_qsort.h" | ||
2397 | |||
2398 | +#if SUHOSIN_PATCH | ||
2399 | +#ifdef ZTS | ||
2400 | +MUTEX_T zend_llist_dprot_mx_reader; | ||
2401 | +MUTEX_T zend_llist_dprot_mx_writer; | ||
2402 | +unsigned int zend_llist_dprot_reader; | ||
2403 | +#endif | ||
2404 | +unsigned int zend_llist_dprot_counter; | ||
2405 | +unsigned int zend_llist_dprot_curmax; | ||
2406 | +llist_dtor_func_t *zend_llist_dprot_table = NULL; | ||
2407 | + | ||
2408 | +static void zend_llist_dprot_begin_read() | ||
2409 | +{ | ||
2410 | +#ifdef ZTS | ||
2411 | + tsrm_mutex_lock(zend_llist_dprot_mx_reader); | ||
2412 | + if ((++(zend_llist_dprot_reader)) == 1) { | ||
2413 | + tsrm_mutex_lock(zend_llist_dprot_mx_writer); | ||
2414 | + } | ||
2415 | + tsrm_mutex_unlock(zend_llist_dprot_mx_reader); | ||
2416 | +#endif | ||
2417 | +} | ||
2418 | + | ||
2419 | +static void zend_llist_dprot_end_read() | ||
2420 | +{ | ||
2421 | +#ifdef ZTS | ||
2422 | + tsrm_mutex_lock(zend_llist_dprot_mx_reader); | ||
2423 | + if ((--(zend_llist_dprot_reader)) == 0) { | ||
2424 | + tsrm_mutex_unlock(zend_llist_dprot_mx_writer); | ||
2425 | + } | ||
2426 | + tsrm_mutex_unlock(zend_llist_dprot_mx_reader); | ||
2427 | +#endif | ||
2428 | +} | ||
2429 | + | ||
2430 | +static void zend_llist_dprot_begin_write() | ||
2431 | +{ | ||
2432 | +#ifdef ZTS | ||
2433 | + tsrm_mutex_lock(zend_llist_dprot_mx_writer); | ||
2434 | +#endif | ||
2435 | +} | ||
2436 | + | ||
2437 | +static void zend_llist_dprot_end_write() | ||
2438 | +{ | ||
2439 | +#ifdef ZTS | ||
2440 | + tsrm_mutex_unlock(zend_llist_dprot_mx_writer); | ||
2441 | +#endif | ||
2442 | +} | ||
2443 | + | ||
2444 | +/*ZEND_API void zend_llist_dprot_dtor() | ||
2445 | +{ | ||
2446 | +#ifdef ZTS | ||
2447 | + tsrm_mutex_free(zend_llist_dprot_mx_reader); | ||
2448 | + tsrm_mutex_free(zend_llist_dprot_mx_writer); | ||
2449 | +#endif | ||
2450 | + free(zend_llist_dprot_table); | ||
2451 | +}*/ | ||
2452 | + | ||
2453 | +static void zend_llist_add_destructor(llist_dtor_func_t pDestructor) | ||
2454 | +{ | ||
2455 | + int left, right, mid; | ||
2456 | + zend_bool found = 0; | ||
2457 | + unsigned long value; | ||
2458 | + | ||
2459 | + if (pDestructor == NULL || pDestructor == ZVAL_PTR_DTOR) { | ||
2460 | + return; | ||
2461 | + } | ||
2462 | + | ||
2463 | + if (zend_llist_dprot_table == NULL) { | ||
2464 | +#ifdef ZTS | ||
2465 | + zend_llist_dprot_mx_reader = tsrm_mutex_alloc(); | ||
2466 | + zend_llist_dprot_mx_writer = tsrm_mutex_alloc(); | ||
2467 | + zend_llist_dprot_reader = 0; | ||
2468 | +#endif | ||
2469 | + zend_llist_dprot_counter = 0; | ||
2470 | + zend_llist_dprot_curmax = 256; | ||
2471 | + zend_llist_dprot_table = (llist_dtor_func_t *) malloc(256 * sizeof(llist_dtor_func_t)); | ||
2472 | + } | ||
2473 | + | ||
2474 | + zend_llist_dprot_begin_write(); | ||
2475 | + | ||
2476 | + if (zend_llist_dprot_counter == 0) { | ||
2477 | + zend_llist_dprot_counter++; | ||
2478 | + zend_llist_dprot_table[0] = pDestructor; | ||
2479 | + } else { | ||
2480 | + value = (unsigned long) pDestructor; | ||
2481 | + left = 0; | ||
2482 | + right = zend_llist_dprot_counter-1; | ||
2483 | + mid = 0; | ||
2484 | + | ||
2485 | + while (left < right) { | ||
2486 | + mid = (right - left) >> 1; | ||
2487 | + mid += left; | ||
2488 | + if ((unsigned long)zend_llist_dprot_table[mid] == value) { | ||
2489 | + found = 1; | ||
2490 | + break; | ||
2491 | + } | ||
2492 | + if (value < (unsigned long)zend_llist_dprot_table[mid]) { | ||
2493 | + right = mid-1; | ||
2494 | + } else { | ||
2495 | + left = mid+1; | ||
2496 | + } | ||
2497 | + } | ||
2498 | + if ((unsigned long)zend_llist_dprot_table[left] == value) { | ||
2499 | + found = 1; | ||
2500 | + } | ||
2501 | + | ||
2502 | + if (!found) { | ||
2503 | + | ||
2504 | + if (zend_llist_dprot_counter >= zend_llist_dprot_curmax) { | ||
2505 | + zend_llist_dprot_curmax += 256; | ||
2506 | + zend_llist_dprot_table = (llist_dtor_func_t *) realloc(zend_llist_dprot_table, zend_llist_dprot_curmax * sizeof(llist_dtor_func_t)); | ||
2507 | + } | ||
2508 | + | ||
2509 | + if ((unsigned long)zend_llist_dprot_table[left] < value) { | ||
2510 | + memmove(zend_llist_dprot_table+left+2, zend_llist_dprot_table+left+1, (zend_llist_dprot_counter-left-1)*sizeof(llist_dtor_func_t)); | ||
2511 | + zend_llist_dprot_table[left+1] = pDestructor; | ||
2512 | + } else { | ||
2513 | + memmove(zend_llist_dprot_table+left+1, zend_llist_dprot_table+left, (zend_llist_dprot_counter-left)*sizeof(llist_dtor_func_t)); | ||
2514 | + zend_llist_dprot_table[left] = pDestructor; | ||
2515 | + } | ||
2516 | + | ||
2517 | + zend_llist_dprot_counter++; | ||
2518 | + } | ||
2519 | + } | ||
2520 | + | ||
2521 | + zend_llist_dprot_end_write(); | ||
2522 | +} | ||
2523 | + | ||
2524 | +static void zend_llist_check_destructor(llist_dtor_func_t pDestructor) | ||
2525 | +{ | ||
2526 | + unsigned long value; | ||
2527 | + | ||
2528 | + if (pDestructor == NULL || pDestructor == ZVAL_PTR_DTOR) { | ||
2529 | + return; | ||
2530 | + } | ||
2531 | + | ||
2532 | + zend_llist_dprot_begin_read(); | ||
2533 | + | ||
2534 | + if (zend_llist_dprot_counter > 0) { | ||
2535 | + int left, right, mid; | ||
2536 | + zend_bool found = 0; | ||
2537 | + | ||
2538 | + value = (unsigned long) pDestructor; | ||
2539 | + left = 0; | ||
2540 | + right = zend_llist_dprot_counter-1; | ||
2541 | + | ||
2542 | + while (left < right) { | ||
2543 | + mid = (right - left) >> 1; | ||
2544 | + mid += left; | ||
2545 | + if ((unsigned long)zend_llist_dprot_table[mid] == value) { | ||
2546 | + found = 1; | ||
2547 | + break; | ||
2548 | + } | ||
2549 | + if (value < (unsigned long)zend_llist_dprot_table[mid]) { | ||
2550 | + right = mid-1; | ||
2551 | + } else { | ||
2552 | + left = mid+1; | ||
2553 | + } | ||
2554 | + } | ||
2555 | + if ((unsigned long)zend_llist_dprot_table[left] == value) { | ||
2556 | + found = 1; | ||
2557 | + } | ||
2558 | + | ||
2559 | + if (!found) { | ||
2560 | + zend_llist_dprot_end_read(); | ||
2561 | + | ||
2562 | + zend_suhosin_log(S_MEMORY, "possible memory corruption detected - unknown llist destructor"); | ||
2563 | + exit(1); | ||
2564 | + return; | ||
2565 | + } | ||
2566 | + | ||
2567 | + } | ||
2568 | + | ||
2569 | + zend_llist_dprot_end_read(); | ||
2570 | +} | ||
2571 | +#else | ||
2572 | +#define zend_llist_add_destructor(pDestructor) do {} while(0) | ||
2573 | +#define zend_llist_check_destructor(pDestructor) do {} while(0) | ||
2574 | +#endif | ||
2575 | + | ||
2576 | ZEND_API void zend_llist_init(zend_llist *l, size_t size, llist_dtor_func_t dtor, unsigned char persistent) | ||
2577 | { | ||
2578 | l->head = NULL; | ||
2579 | @@ -30,6 +208,7 @@ | ||
2580 | l->count = 0; | ||
2581 | l->size = size; | ||
2582 | l->dtor = dtor; | ||
2583 | + zend_llist_add_destructor(dtor); | ||
2584 | l->persistent = persistent; | ||
2585 | } | ||
2586 | |||
2587 | @@ -81,6 +260,7 @@ | ||
2588 | } else {\ | ||
2589 | (l)->tail = (current)->prev;\ | ||
2590 | }\ | ||
2591 | + zend_llist_check_destructor((l)->dtor); \ | ||
2592 | if ((l)->dtor) {\ | ||
2593 | (l)->dtor((current)->data);\ | ||
2594 | }\ | ||
2595 | @@ -108,6 +288,7 @@ | ||
2596 | { | ||
2597 | zend_llist_element *current=l->head, *next; | ||
2598 | |||
2599 | + zend_llist_check_destructor(l->dtor); | ||
2600 | while (current) { | ||
2601 | next = current->next; | ||
2602 | if (l->dtor) { | ||
2603 | @@ -133,6 +314,7 @@ | ||
2604 | zend_llist_element *old_tail; | ||
2605 | void *data; | ||
2606 | |||
2607 | + zend_llist_check_destructor(l->dtor); | ||
2608 | if ((old_tail = l->tail)) { | ||
2609 | if (old_tail->prev) { | ||
2610 | old_tail->prev->next = NULL; | ||
2611 | diff -Naur php-5.2.4/Zend/ZendTS.dsp php-5.2.4-suhosin/Zend/ZendTS.dsp | ||
2612 | --- php-5.2.4/Zend/ZendTS.dsp 2006-12-05 09:07:57.000000000 +0100 | ||
2613 | +++ php-5.2.4-suhosin/Zend/ZendTS.dsp 2007-09-07 20:11:39.000000000 +0200 | ||
2614 | @@ -273,6 +273,10 @@ | ||
2615 | # End Source File | ||
2616 | # Begin Source File | ||
2617 | |||
2618 | +SOURCE=.\zend_canary.c | ||
2619 | +# End Source File | ||
2620 | +# Begin Source File | ||
2621 | + | ||
2622 | SOURCE=.\zend_ts_hash.c | ||
2623 | # End Source File | ||
2624 | # Begin Source File |