-
Notifications
You must be signed in to change notification settings - Fork 0
/
suhosin-patch-5.2.16-0.9.7.patch
2640 lines (2518 loc) · 92.8 KB
/
suhosin-patch-5.2.16-0.9.7.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff -Nura php-5.2.16/TSRM/TSRM.h suhosin-patch-5.2.16-0.9.7/TSRM/TSRM.h
--- php-5.2.16/TSRM/TSRM.h 2008-12-31 12:17:49.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/TSRM/TSRM.h 2010-12-30 16:48:25.000000000 +0100
@@ -38,6 +38,13 @@
typedef unsigned long tsrm_uintptr_t;
#endif
+#if SUHOSIN_PATCH
+# if HAVE_REALPATH
+# undef realpath
+# define realpath php_realpath
+# endif
+#endif
+
/* Only compile multi-threading functions if we're in ZTS mode */
#ifdef ZTS
@@ -93,6 +100,7 @@
#define THREAD_HASH_OF(thr,ts) (unsigned long)thr%(unsigned long)ts
+
#ifdef __cplusplus
extern "C" {
#endif
diff -Nura php-5.2.16/TSRM/tsrm_virtual_cwd.c suhosin-patch-5.2.16-0.9.7/TSRM/tsrm_virtual_cwd.c
--- php-5.2.16/TSRM/tsrm_virtual_cwd.c 2010-01-03 10:23:27.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/TSRM/tsrm_virtual_cwd.c 2010-12-30 16:48:25.000000000 +0100
@@ -273,6 +273,191 @@
}
/* }}} */
+#if SUHOSIN_PATCH
+CWD_API char *php_realpath(const char *path, char *resolved)
+{
+ struct stat sb;
+ char *p, *q, *s;
+ size_t left_len, resolved_len;
+ unsigned symlinks;
+ int serrno, slen;
+ int is_dir = 1;
+ char left[PATH_MAX], next_token[PATH_MAX], symlink[PATH_MAX];
+
+ serrno = errno;
+ symlinks = 0;
+ if (path[0] == '/') {
+ resolved[0] = '/';
+ resolved[1] = '\0';
+ if (path[1] == '\0')
+ return (resolved);
+ resolved_len = 1;
+ left_len = strlcpy(left, path + 1, sizeof(left));
+ } else {
+ if (getcwd(resolved, PATH_MAX) == NULL) {
+ strlcpy(resolved, ".", PATH_MAX);
+ return (NULL);
+ }
+ resolved_len = strlen(resolved);
+ left_len = strlcpy(left, path, sizeof(left));
+ }
+ if (left_len >= sizeof(left) || resolved_len >= PATH_MAX) {
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+
+ /*
+ * Iterate over path components in `left'.
+ */
+ while (left_len != 0) {
+ /*
+ * Extract the next path component and adjust `left'
+ * and its length.
+ */
+ p = strchr(left, '/');
+ s = p ? p : left + left_len;
+ if (s - left >= sizeof(next_token)) {
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ memcpy(next_token, left, s - left);
+ next_token[s - left] = '\0';
+ left_len -= s - left;
+ if (p != NULL)
+ memmove(left, s + 1, left_len + 1);
+ if (resolved[resolved_len - 1] != '/') {
+ if (resolved_len + 1 >= PATH_MAX) {
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ resolved[resolved_len++] = '/';
+ resolved[resolved_len] = '\0';
+ }
+ if (next_token[0] == '\0')
+ continue;
+ else if (strcmp(next_token, ".") == 0){
+ if (!is_dir) {
+ resolved_len = strlcat(resolved, "#", PATH_MAX);
+ if (resolved_len >= PATH_MAX) {
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ return resolved;
+ }
+ continue;
+ } else if (strcmp(next_token, "..") == 0) {
+ /*
+ * Strip the last path component except when we have
+ * single "/"
+ */
+ if (!is_dir) {
+ errno = ENOENT;
+ return (NULL);
+ }
+ if (resolved_len > 1) {
+ resolved[resolved_len - 1] = '\0';
+ q = strrchr(resolved, '/');
+ *q = '\0';
+ resolved_len = q - resolved;
+ }
+ continue;
+ }
+
+ /*
+ * Append the next path component and lstat() it. If
+ * lstat() fails we still can return successfully if
+ * there are no more path components left.
+ */
+ resolved_len = strlcat(resolved, next_token, PATH_MAX);
+ if (resolved_len >= PATH_MAX) {
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ if (lstat(resolved, &sb) != 0) {
+ if (errno == ENOENT) {
+ if (p == NULL) {
+ errno = serrno;
+ return NULL;
+ return (resolved);
+ } /*else if (strstr(left, "/.") == NULL && strstr(left, "./") == NULL) {
+ resolved_len = strlcat(resolved, "/", PATH_MAX);
+ resolved_len = strlcat(resolved, left, PATH_MAX);
+ if (resolved_len >= PATH_MAX) {
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ errno = serrno;
+ return (resolved);
+ } */
+ }
+ return (NULL);
+ }
+ if (S_ISLNK(sb.st_mode)) {
+ if (symlinks++ > MAXSYMLINKS) {
+ errno = ELOOP;
+ return (NULL);
+ }
+ slen = readlink(resolved, symlink, sizeof(symlink) - 1);
+ if (slen < 0)
+ return (NULL);
+ symlink[slen] = '\0';
+ if (symlink[0] == '/') {
+ resolved[1] = 0;
+ resolved_len = 1;
+ } else if (resolved_len > 1) {
+ /* Strip the last path component. */
+ resolved[resolved_len - 1] = '\0';
+ q = strrchr(resolved, '/');
+ *q = '\0';
+ resolved_len = q - resolved;
+ }
+
+ /*
+ * If there are any path components left, then
+ * append them to symlink. The result is placed
+ * in `left'.
+ */
+ if (p != NULL) {
+ if (symlink[slen - 1] != '/') {
+ if (slen + 1 >= sizeof(symlink)) {
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ symlink[slen] = '/';
+ symlink[slen + 1] = 0;
+ }
+ left_len = strlcat(symlink, left, sizeof(left));
+ if (left_len >= sizeof(left)) {
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+ }
+ left_len = strlcpy(left, symlink, sizeof(left));
+ } else {
+ if (S_ISDIR(sb.st_mode)) {
+ is_dir = 1;
+ } else {
+ is_dir = 0;
+ }
+ }
+ }
+
+ /*
+ * Remove trailing slash except when the resolved pathname
+ * is a single "/".
+ */
+ if (resolved_len > 1 && resolved[resolved_len - 1] == '/') {
+ if (!is_dir) {
+ errno = ENOENT;
+ return (NULL);
+ }
+ resolved[resolved_len - 1] = '\0';
+ }
+ return (resolved);
+}
+#endif
+
+
CWD_API void virtual_cwd_startup(void) /* {{{ */
{
char cwd[MAXPATHLEN];
diff -Nura php-5.2.16/TSRM/tsrm_virtual_cwd.h suhosin-patch-5.2.16-0.9.7/TSRM/tsrm_virtual_cwd.h
--- php-5.2.16/TSRM/tsrm_virtual_cwd.h 2010-01-03 10:23:27.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/TSRM/tsrm_virtual_cwd.h 2010-12-30 16:48:25.000000000 +0100
@@ -139,6 +139,22 @@
typedef int (*verify_path_func)(const cwd_state *);
+#ifndef HAVE_STRLCPY
+CWD_API size_t php_strlcpy(char *dst, const char *src, size_t siz);
+#undef strlcpy
+#define strlcpy php_strlcpy
+#endif
+
+#ifndef HAVE_STRLCAT
+CWD_API size_t php_strlcat(char *dst, const char *src, size_t siz);
+#undef strlcat
+#define strlcat php_strlcat
+#endif
+
+
+#if SUHOSIN_PATCH
+CWD_API char *php_realpath(const char *path, char *resolved);
+#endif
CWD_API void virtual_cwd_startup(void);
CWD_API void virtual_cwd_shutdown(void);
CWD_API char *virtual_getcwd_ex(size_t *length TSRMLS_DC);
diff -Nura php-5.2.16/Zend/Makefile.am suhosin-patch-5.2.16-0.9.7/Zend/Makefile.am
--- php-5.2.16/Zend/Makefile.am 2006-12-05 09:07:57.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/Makefile.am 2010-12-30 16:48:25.000000000 +0100
@@ -17,7 +17,7 @@
zend_objects_API.c zend_ts_hash.c zend_stream.c \
zend_default_classes.c \
zend_iterators.c zend_interfaces.c zend_exceptions.c \
- zend_strtod.c zend_multibyte.c
+ zend_strtod.c zend_multibyte.c zend_canary.c
libZend_la_LDFLAGS =
libZend_la_LIBADD = @ZEND_EXTRA_LIBS@
diff -Nura php-5.2.16/Zend/Zend.dsp suhosin-patch-5.2.16-0.9.7/Zend/Zend.dsp
--- php-5.2.16/Zend/Zend.dsp 2006-12-05 09:07:57.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/Zend.dsp 2010-12-30 16:48:25.000000000 +0100
@@ -239,6 +239,10 @@
# End Source File
# Begin Source File
+SOURCE=.\zend_canary.c
+# End Source File
+# Begin Source File
+
SOURCE=.\zend_ts_hash.c
# End Source File
# Begin Source File
diff -Nura php-5.2.16/Zend/ZendTS.dsp suhosin-patch-5.2.16-0.9.7/Zend/ZendTS.dsp
--- php-5.2.16/Zend/ZendTS.dsp 2006-12-05 09:07:57.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/ZendTS.dsp 2010-12-30 16:48:25.000000000 +0100
@@ -273,6 +273,10 @@
# End Source File
# Begin Source File
+SOURCE=.\zend_canary.c
+# End Source File
+# Begin Source File
+
SOURCE=.\zend_ts_hash.c
# End Source File
# Begin Source File
diff -Nura php-5.2.16/Zend/zend.c suhosin-patch-5.2.16-0.9.7/Zend/zend.c
--- php-5.2.16/Zend/zend.c 2010-01-05 21:46:53.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend.c 2010-12-30 16:48:25.000000000 +0100
@@ -57,7 +57,9 @@
ZEND_API void (*zend_error_cb)(int type, const char *error_filename, const uint error_lineno, const char *format, va_list args);
int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
-
+#if SUHOSIN_PATCH
+ZEND_API void (*zend_suhosin_log)(int loglevel, char *fmt, ...);
+#endif
void (*zend_on_timeout)(int seconds TSRMLS_DC);
static void (*zend_message_dispatcher_p)(long message, void *data);
@@ -74,9 +76,88 @@
return SUCCESS;
}
+#if SUHOSIN_PATCH
+static ZEND_INI_MH(OnUpdateSuhosin_log_syslog)
+{
+ if (!new_value) {
+ SPG(log_syslog) = S_ALL & ~S_SQL | S_MEMORY;
+ } else {
+ SPG(log_syslog) = atoi(new_value) | S_MEMORY;
+ }
+ return SUCCESS;
+}
+static ZEND_INI_MH(OnUpdateSuhosin_log_syslog_facility)
+{
+ if (!new_value) {
+ SPG(log_syslog_facility) = LOG_USER;
+ } else {
+ SPG(log_syslog_facility) = atoi(new_value);
+ }
+ return SUCCESS;
+}
+static ZEND_INI_MH(OnUpdateSuhosin_log_syslog_priority)
+{
+ if (!new_value) {
+ SPG(log_syslog_priority) = LOG_ALERT;
+ } else {
+ SPG(log_syslog_priority) = atoi(new_value);
+ }
+ return SUCCESS;
+}
+static ZEND_INI_MH(OnUpdateSuhosin_log_sapi)
+{
+ if (!new_value) {
+ SPG(log_sapi) = S_ALL & ~S_SQL;
+ } else {
+ SPG(log_sapi) = atoi(new_value);
+ }
+ return SUCCESS;
+}
+static ZEND_INI_MH(OnUpdateSuhosin_log_script)
+{
+ if (!new_value) {
+ SPG(log_script) = S_ALL & ~S_MEMORY;
+ } else {
+ SPG(log_script) = atoi(new_value) & (~S_MEMORY) & (~S_INTERNAL);
+ }
+ return SUCCESS;
+}
+static ZEND_INI_MH(OnUpdateSuhosin_log_scriptname)
+{
+ if (SPG(log_scriptname)) {
+ pefree(SPG(log_scriptname),1);
+ }
+ SPG(log_scriptname) = NULL;
+ if (new_value) {
+ SPG(log_scriptname) = pestrdup(new_value,1);
+ }
+ return SUCCESS;
+}
+static ZEND_INI_MH(OnUpdateSuhosin_log_phpscript)
+{
+ if (!new_value) {
+ SPG(log_phpscript) = S_ALL & ~S_MEMORY;
+ } else {
+ SPG(log_phpscript) = atoi(new_value) & (~S_MEMORY) & (~S_INTERNAL);
+ }
+ return SUCCESS;
+}
+#endif
ZEND_INI_BEGIN()
ZEND_INI_ENTRY("error_reporting", NULL, ZEND_INI_ALL, OnUpdateErrorReporting)
+#if SUHOSIN_PATCH
+ ZEND_INI_ENTRY("suhosin.log.syslog", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_syslog)
+ ZEND_INI_ENTRY("suhosin.log.syslog.facility", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_syslog_facility)
+ ZEND_INI_ENTRY("suhosin.log.syslog.priority", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_syslog_priority)
+ ZEND_INI_ENTRY("suhosin.log.sapi", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_sapi)
+ ZEND_INI_ENTRY("suhosin.log.script", NULL, ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_script)
+ ZEND_INI_ENTRY("suhosin.log.script.name", NULL, ZEND_INI_SYSTEM, OnUpdateSuhosin_log_scriptname)
+ 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)
+ ZEND_INI_ENTRY("suhosin.log.phpscript", "0", ZEND_INI_PERDIR|ZEND_INI_SYSTEM, OnUpdateSuhosin_log_phpscript)
+ 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)
+ 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)
+#endif
STD_ZEND_INI_BOOLEAN("zend.ze1_compatibility_mode", "0", ZEND_INI_ALL, OnUpdateBool, ze1_compatibility_mode, zend_executor_globals, executor_globals)
#ifdef ZEND_MULTIBYTE
STD_ZEND_INI_BOOLEAN("detect_unicode", "1", ZEND_INI_ALL, OnUpdateBool, detect_unicode, zend_compiler_globals, compiler_globals)
diff -Nura php-5.2.16/Zend/zend.h suhosin-patch-5.2.16-0.9.7/Zend/zend.h
--- php-5.2.16/Zend/zend.h 2010-01-15 19:26:53.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend.h 2010-12-30 16:48:25.000000000 +0100
@@ -550,6 +550,9 @@
extern ZEND_API int (*zend_stream_open_function)(const char *filename, zend_file_handle *handle TSRMLS_DC);
extern int (*zend_vspprintf)(char **pbuf, size_t max_len, const char *format, va_list ap);
extern ZEND_API char *(*zend_getenv)(char *name, size_t name_len TSRMLS_DC);
+#if SUHOSIN_PATCH
+extern ZEND_API void (*zend_suhosin_log)(int loglevel, char *fmt, ...);
+#endif
ZEND_API void zend_error(int type, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
@@ -681,6 +684,13 @@
#include "zend_operators.h"
#include "zend_variables.h"
+#if SUHOSIN_PATCH
+#include "suhosin_globals.h"
+#include "php_syslog.h"
+
+ZEND_API size_t zend_canary();
+#endif
+
#endif /* ZEND_H */
/*
diff -Nura php-5.2.16/Zend/zend_alloc.c suhosin-patch-5.2.16-0.9.7/Zend/zend_alloc.c
--- php-5.2.16/Zend/zend_alloc.c 2010-07-14 12:27:08.000000000 +0200
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend_alloc.c 2010-12-30 16:48:25.000000000 +0100
@@ -316,13 +316,26 @@
#define MEM_BLOCK_GUARD 0x2A8FCC84
#define MEM_BLOCK_LEAK 0x6C5E8F2D
+#if SUHOSIN_PATCH
+# define CANARY_SIZE sizeof(size_t)
+#else
+# define CANARY_SIZE 0
+#endif
+
/* mm block type */
typedef struct _zend_mm_block_info {
#if ZEND_MM_COOKIES
size_t _cookie;
#endif
- size_t _size;
- size_t _prev;
+#if SUHOSIN_PATCH
+ size_t canary_1;
+#endif
+ size_t _size;
+ size_t _prev;
+#if SUHOSIN_PATCH
+ size_t size;
+ size_t canary_2;
+#endif
} zend_mm_block_info;
#if ZEND_DEBUG
@@ -428,6 +441,9 @@
int miss;
} cache_stat[ZEND_MM_NUM_BUCKETS+1];
#endif
+#if SUHOSIN_PATCH
+ size_t canary_1,canary_2,canary_3;
+#endif
};
#define ZEND_MM_SMALL_FREE_BUCKET(heap, index) \
@@ -517,15 +533,15 @@
#define ZEND_MM_ALIGNED_SIZE(size) ((size + ZEND_MM_ALIGNMENT - 1) & ZEND_MM_ALIGNMENT_MASK)
#define ZEND_MM_ALIGNED_HEADER_SIZE ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_block))
#define ZEND_MM_ALIGNED_FREE_HEADER_SIZE ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_small_free_block))
-#define ZEND_MM_MIN_ALLOC_BLOCK_SIZE ZEND_MM_ALIGNED_SIZE(ZEND_MM_ALIGNED_HEADER_SIZE + END_MAGIC_SIZE)
+#define ZEND_MM_MIN_ALLOC_BLOCK_SIZE ZEND_MM_ALIGNED_SIZE(ZEND_MM_ALIGNED_HEADER_SIZE + END_MAGIC_SIZE + CANARY_SIZE)
#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)
#define ZEND_MM_ALIGNED_SEGMENT_SIZE ZEND_MM_ALIGNED_SIZE(sizeof(zend_mm_segment))
-#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)
+#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)
#define ZEND_MM_MAX_SMALL_SIZE ((ZEND_MM_NUM_BUCKETS<<ZEND_MM_ALIGNMENT_LOG2)+ZEND_MM_ALIGNED_MIN_HEADER_SIZE)
-#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)))
+#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)))
#define ZEND_MM_BUCKET_INDEX(true_size) ((true_size>>ZEND_MM_ALIGNMENT_LOG2)-(ZEND_MM_ALIGNED_MIN_HEADER_SIZE>>ZEND_MM_ALIGNMENT_LOG2))
@@ -587,6 +603,48 @@
#endif
+#if SUHOSIN_PATCH
+
+# define SUHOSIN_MM_CHECK_CANARIES(block, MFUNCTION) do { \
+ char *p = SUHOSIN_MM_END_CANARY_PTR(block); size_t check; \
+ if (((block)->info.canary_1 != heap->canary_1) || ((block)->info.canary_2 != heap->canary_2)) { \
+ canary_mismatch: \
+ zend_suhosin_log(S_MEMORY, "canary mismatch on " MFUNCTION " - heap overflow detected"); \
+ exit(1); \
+ } \
+ memcpy(&check, p, CANARY_SIZE); \
+ if (check != heap->canary_3) { \
+ zend_suhosin_log(S_MEMORY, "canary mismatch on " MFUNCTION " - heap overflow detected"); \
+ exit(1); \
+ goto canary_mismatch; \
+ } \
+ } while (0)
+
+# define SUHOSIN_MM_SET_CANARIES(block) do { \
+ (block)->info.canary_1 = heap->canary_1; \
+ (block)->info.canary_2 = heap->canary_2; \
+ } while (0)
+
+# define SUHOSIN_MM_END_CANARY_PTR(block) \
+ (char *)(((char*)(ZEND_MM_DATA_OF(block))) + ((zend_mm_block*)(block))->info.size + END_MAGIC_SIZE)
+
+# define SUHOSIN_MM_SET_END_CANARY(block) do { \
+ char *p = SUHOSIN_MM_END_CANARY_PTR(block); \
+ memcpy(p, &heap->canary_3, CANARY_SIZE); \
+ } while (0)
+
+#else
+
+# define SUHOSIN_MM_CHECK_CANARIES(block)
+
+# define SUHOSIN_MM_SET_CANARIES(block)
+
+# define SUHOSIN_MM_END_CANARY_PTR(block)
+
+# define SUHOSIN_MM_SET_END_CANARY(block)
+
+#endif
+
#if ZEND_MM_HEAP_PROTECTION
@@ -795,6 +853,12 @@
if (EXPECTED(prev == mm_block)) {
zend_mm_free_block **rp, **cp;
+#if SUHOSIN_PATCH
+ if (next != mm_block) {
+ zend_suhosin_log(S_MEMORY, "heap corrupt on efree() - heap corruption detected");
+ exit(1);
+ }
+#endif
#if ZEND_MM_SAFE_UNLINKING
if (UNEXPECTED(next != mm_block)) {
zend_mm_panic("zend_mm_heap corrupted");
@@ -833,6 +897,12 @@
}
} else {
+#if SUHOSIN_PATCH
+ if (prev->next_free_block != mm_block || next->prev_free_block != mm_block) {
+ zend_suhosin_log(S_MEMORY, "linked list corrupt on efree() - heap corruption detected");
+ exit(1);
+ }
+#endif
#if ZEND_MM_SAFE_UNLINKING
if (UNEXPECTED(prev->next_free_block != mm_block) || UNEXPECTED(next->prev_free_block != mm_block)) {
zend_mm_panic("zend_mm_heap corrupted");
@@ -880,6 +950,11 @@
heap->large_free_buckets[i] = NULL;
}
heap->rest_buckets[0] = heap->rest_buckets[1] = ZEND_MM_REST_BUCKET(heap);
+#if SUHOSIN_PATCH
+ heap->canary_1 = zend_canary();
+ heap->canary_2 = zend_canary();
+ heap->canary_3 = zend_canary();
+#endif
}
static void zend_mm_del_segment(zend_mm_heap *heap, zend_mm_segment *segment)
@@ -1784,6 +1859,11 @@
best_fit = heap->cache[index];
heap->cache[index] = best_fit->prev_free_block;
heap->cached -= true_size;
+#if SUHOSIN_PATCH
+ SUHOSIN_MM_SET_CANARIES(best_fit);
+ ((zend_mm_block*)best_fit)->info.size = size;
+ SUHOSIN_MM_SET_END_CANARY(best_fit);
+#endif
ZEND_MM_CHECK_MAGIC(best_fit, MEM_BLOCK_CACHED);
ZEND_MM_SET_DEBUG_INFO(best_fit, size, 1, 0);
return ZEND_MM_DATA_OF(best_fit);
@@ -1923,6 +2003,12 @@
ZEND_MM_SET_DEBUG_INFO(best_fit, size, 1, 1);
+#if SUHOSIN_PATCH
+ SUHOSIN_MM_SET_CANARIES(best_fit);
+ ((zend_mm_block*)best_fit)->info.size = size;
+ SUHOSIN_MM_SET_END_CANARY(best_fit);
+#endif
+
heap->size += true_size;
if (heap->peak < heap->size) {
heap->peak = heap->size;
@@ -1946,6 +2032,9 @@
mm_block = ZEND_MM_HEADER_OF(p);
size = ZEND_MM_BLOCK_SIZE(mm_block);
+#if SUHOSIN_PATCH
+ SUHOSIN_MM_CHECK_CANARIES(mm_block, "efree()");
+#endif
ZEND_MM_CHECK_PROTECTION(mm_block);
#if ZEND_DEBUG || ZEND_MM_HEAP_PROTECTION
@@ -2008,6 +2097,9 @@
mm_block = ZEND_MM_HEADER_OF(p);
true_size = ZEND_MM_TRUE_SIZE(size);
orig_size = ZEND_MM_BLOCK_SIZE(mm_block);
+#if SUHOSIN_PATCH
+ SUHOSIN_MM_CHECK_CANARIES(mm_block, "erealloc()");
+#endif
ZEND_MM_CHECK_PROTECTION(mm_block);
if (UNEXPECTED(true_size < size)) {
@@ -2039,6 +2131,11 @@
HANDLE_UNBLOCK_INTERRUPTIONS();
}
ZEND_MM_SET_DEBUG_INFO(mm_block, size, 0, 0);
+#if SUHOSIN_PATCH
+ SUHOSIN_MM_SET_CANARIES(mm_block);
+ ((zend_mm_block*)mm_block)->info.size = size;
+ SUHOSIN_MM_SET_END_CANARY(mm_block);
+#endif
return p;
}
@@ -2058,13 +2155,18 @@
heap->cache[index] = best_fit->prev_free_block;
ZEND_MM_CHECK_MAGIC(best_fit, MEM_BLOCK_CACHED);
ZEND_MM_SET_DEBUG_INFO(best_fit, size, 1, 0);
+#if SUHOSIN_PATCH
+ SUHOSIN_MM_SET_CANARIES(best_fit);
+ ((zend_mm_block*)best_fit)->info.size = size;
+ SUHOSIN_MM_SET_END_CANARY(best_fit);
+#endif
ptr = ZEND_MM_DATA_OF(best_fit);
#if ZEND_DEBUG || ZEND_MM_HEAP_PROTECTION
memcpy(ptr, p, mm_block->debug.size);
#else
- memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE);
+ memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE - CANARY_SIZE);
#endif
heap->cached -= true_size - orig_size;
@@ -2122,6 +2224,11 @@
if (heap->peak < heap->size) {
heap->peak = heap->size;
}
+#if SUHOSIN_PATCH
+ SUHOSIN_MM_SET_CANARIES(mm_block);
+ ((zend_mm_block*)mm_block)->info.size = size;
+ SUHOSIN_MM_SET_END_CANARY(mm_block);
+#endif
HANDLE_UNBLOCK_INTERRUPTIONS();
return p;
} else if (ZEND_MM_IS_FIRST_BLOCK(mm_block) &&
@@ -2225,6 +2332,11 @@
}
HANDLE_UNBLOCK_INTERRUPTIONS();
+#if SUHOSIN_PATCH
+ SUHOSIN_MM_SET_CANARIES(mm_block);
+ ((zend_mm_block*)mm_block)->info.size = size;
+ SUHOSIN_MM_SET_END_CANARY(mm_block);
+#endif
return ZEND_MM_DATA_OF(mm_block);
}
@@ -2232,7 +2344,7 @@
#if ZEND_DEBUG || ZEND_MM_HEAP_PROTECTION
memcpy(ptr, p, mm_block->debug.size);
#else
- memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE);
+ memcpy(ptr, p, orig_size - ZEND_MM_ALIGNED_HEADER_SIZE - CANARY_SIZE);
#endif
_zend_mm_free_int(heap, p ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC);
return ptr;
@@ -2499,6 +2611,17 @@
zend_mm_shutdown(AG(mm_heap), full_shutdown, silent);
}
+#if SUHOSIN_PATCH
+ZEND_API void suhosin_clear_mm_canaries(TSRMLS_D)
+{
+/* NOT HERE
+
+ AG(mm_heap)->canary_1 = zend_canary();
+ AG(mm_heap)->canary_2 = zend_canary();
+ AG(mm_heap)->canary_3 = zend_canary(); */
+}
+#endif
+
static void alloc_globals_ctor(zend_alloc_globals *alloc_globals TSRMLS_DC)
{
char *tmp;
diff -Nura php-5.2.16/Zend/zend_alloc.h suhosin-patch-5.2.16-0.9.7/Zend/zend_alloc.h
--- php-5.2.16/Zend/zend_alloc.h 2010-01-05 21:46:53.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend_alloc.h 2010-12-30 16:48:25.000000000 +0100
@@ -129,6 +129,9 @@
ZEND_API void start_memory_manager(TSRMLS_D);
ZEND_API void shutdown_memory_manager(int silent, int full_shutdown TSRMLS_DC);
+#if SUHOSIN_PATCH
+ZEND_API void suhosin_clear_mm_canaries(TSRMLS_D);
+#endif
ZEND_API int is_zend_mm(TSRMLS_D);
#if ZEND_DEBUG
diff -Nura php-5.2.16/Zend/zend_canary.c suhosin-patch-5.2.16-0.9.7/Zend/zend_canary.c
--- php-5.2.16/Zend/zend_canary.c 1970-01-01 01:00:00.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend_canary.c 2010-12-30 16:48:25.000000000 +0100
@@ -0,0 +1,64 @@
+/*
+ +----------------------------------------------------------------------+
+ | Suhosin-Patch for PHP |
+ +----------------------------------------------------------------------+
+ | Copyright (c) 2004-2006 Stefan Esser |
+ +----------------------------------------------------------------------+
+ | This source file is subject to version 2.02 of the PHP license, |
+ | that is bundled with this package in the file LICENSE, and is |
+ | available at through the world-wide-web at |
+ | http://www.php.net/license/2_02.txt. |
+ | If you did not receive a copy of the PHP license and are unable to |
+ | obtain it through the world-wide-web, please send a note to |
+ | [email protected] so we can mail you a copy immediately. |
+ +----------------------------------------------------------------------+
+ | Author: Stefan Esser <[email protected]> |
+ +----------------------------------------------------------------------+
+ */
+/* $Id: zend_canary.c,v 1.1 2004/11/26 12:45:41 ionic Exp $ */
+
+#include "zend.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+
+#if SUHOSIN_PATCH
+
+static size_t last_canary = 0x73625123;
+
+/* will be replaced later with more compatible method */
+ZEND_API size_t zend_canary()
+{
+ time_t t;
+ size_t canary;
+ int fd;
+
+#ifndef PHP_WIN32
+ fd = open("/dev/urandom", 0);
+ if (fd != -1) {
+ int r = read(fd, &canary, sizeof(canary));
+ close(fd);
+ if (r == sizeof(canary)) {
+ return (canary);
+ }
+ }
+#endif
+ /* not good but we never want to do this */
+ time(&t);
+ canary = *(unsigned int *)&t + getpid() << 16 + last_canary;
+ last_canary ^= (canary << 5) | (canary >> (32-5));
+ return (canary);
+}
+
+#endif
+
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * End:
+ * vim600: sw=4 ts=4 fdm=marker
+ * vim<600: sw=4 ts=4
+ */
diff -Nura php-5.2.16/Zend/zend_compile.c suhosin-patch-5.2.16-0.9.7/Zend/zend_compile.c
--- php-5.2.16/Zend/zend_compile.c 2010-08-12 19:27:16.000000000 +0200
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend_compile.c 2010-12-30 16:48:25.000000000 +0100
@@ -54,7 +54,6 @@
property_info->name = zend_strndup(property_info->name, property_info->name_length);
}
-
static void zend_destroy_property_info(zend_property_info *property_info)
{
efree(property_info->name);
@@ -68,6 +67,10 @@
{
free(property_info->name);
}
+#if SUHOSIN_PATCH
+void *suhosin_zend_destroy_property_info_internal = zend_destroy_property_info_internal;
+void *suhosin_zend_destroy_property_info = zend_destroy_property_info;
+#endif
static void build_runtime_defined_function_key(zval *result, char *name, int name_length TSRMLS_DC)
{
diff -Nura php-5.2.16/Zend/zend_compile.h suhosin-patch-5.2.16-0.9.7/Zend/zend_compile.h
--- php-5.2.16/Zend/zend_compile.h 2010-01-05 21:46:53.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend_compile.h 2010-12-30 16:48:25.000000000 +0100
@@ -568,6 +568,11 @@
int zendlex(znode *zendlval TSRMLS_DC);
+#if SUHOSIN_PATCH
+extern void *suhosin_zend_destroy_property_info_internal;
+extern void *suhosin_zend_destroy_property_info;
+#endif
+
/* BEGIN: OPCODES */
#include "zend_vm_opcodes.h"
@@ -693,6 +698,7 @@
#define ZEND_RETURNS_FUNCTION 1<<0
#define ZEND_RETURNS_NEW 1<<1
+
END_EXTERN_C()
#define ZEND_CLONE_FUNC_NAME "__clone"
diff -Nura php-5.2.16/Zend/zend_constants.c suhosin-patch-5.2.16-0.9.7/Zend/zend_constants.c
--- php-5.2.16/Zend/zend_constants.c 2010-02-08 13:31:33.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend_constants.c 2010-12-30 16:48:25.000000000 +0100
@@ -110,6 +110,75 @@
REGISTER_MAIN_LONG_CONSTANT("E_USER_NOTICE", E_USER_NOTICE, CONST_PERSISTENT | CONST_CS);
REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS);
+#if SUHOSIN_PATCH
+ REGISTER_MAIN_LONG_CONSTANT("S_MEMORY", S_MEMORY, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_VARS", S_VARS, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_FILES", S_FILES, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_INCLUDE", S_INCLUDE, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_SQL", S_SQL, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_EXECUTOR", S_EXECUTOR, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_MAIL", S_MAIL, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_SESSION", S_SESSION, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_MISC", S_MISC, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_INTERNAL", S_INTERNAL, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("S_ALL", S_ALL, CONST_PERSISTENT | CONST_CS);
+
+ /* error levels */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_CS | CONST_PERSISTENT); /* system unusable */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_CS | CONST_PERSISTENT); /* immediate action required */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_CS | CONST_PERSISTENT); /* critical conditions */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_ERR", LOG_ERR, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_WARNING", LOG_WARNING, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_NOTICE", LOG_NOTICE, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_INFO", LOG_INFO, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_DEBUG", LOG_DEBUG, CONST_CS | CONST_PERSISTENT);
+ /* facility: type of program logging the message */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_KERN", LOG_KERN, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_USER", LOG_USER, CONST_CS | CONST_PERSISTENT); /* generic user level */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_MAIL", LOG_MAIL, CONST_CS | CONST_PERSISTENT); /* log to email */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_DAEMON", LOG_DAEMON, CONST_CS | CONST_PERSISTENT); /* other system daemons */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_AUTH", LOG_AUTH, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_SYSLOG", LOG_SYSLOG, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_LPR", LOG_LPR, CONST_CS | CONST_PERSISTENT);
+#ifdef LOG_NEWS
+ /* No LOG_NEWS on HP-UX */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_NEWS", LOG_NEWS, CONST_CS | CONST_PERSISTENT); /* usenet new */
+#endif
+#ifdef LOG_UUCP
+ /* No LOG_UUCP on HP-UX */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_UUCP", LOG_UUCP, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef LOG_CRON
+ /* apparently some systems don't have this one */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_CRON", LOG_CRON, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef LOG_AUTHPRIV
+ /* AIX doesn't have LOG_AUTHPRIV */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_AUTHPRIV", LOG_AUTHPRIV, CONST_CS | CONST_PERSISTENT);
+#endif
+#if !defined(PHP_WIN32) && !defined(NETWARE)
+ REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL0", LOG_LOCAL0, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL1", LOG_LOCAL1, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL2", LOG_LOCAL2, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL3", LOG_LOCAL3, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL4", LOG_LOCAL4, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL5", LOG_LOCAL5, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL6", LOG_LOCAL6, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_LOCAL7", LOG_LOCAL7, CONST_CS | CONST_PERSISTENT);
+#endif
+ /* options */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_PID", LOG_PID, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_CONS", LOG_CONS, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_ODELAY", LOG_ODELAY, CONST_CS | CONST_PERSISTENT);
+ REGISTER_MAIN_LONG_CONSTANT("LOG_NDELAY", LOG_NDELAY, CONST_CS | CONST_PERSISTENT);
+#ifdef LOG_NOWAIT
+ REGISTER_MAIN_LONG_CONSTANT("LOG_NOWAIT", LOG_NOWAIT, CONST_CS | CONST_PERSISTENT);
+#endif
+#ifdef LOG_PERROR
+ /* AIX doesn't have LOG_PERROR */
+ REGISTER_MAIN_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_CS | CONST_PERSISTENT); /*log to stderr*/
+#endif
+#endif
/* true/false constants */
{
diff -Nura php-5.2.16/Zend/zend_errors.h suhosin-patch-5.2.16-0.9.7/Zend/zend_errors.h
--- php-5.2.16/Zend/zend_errors.h 2010-01-05 21:46:53.000000000 +0100
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend_errors.h 2010-12-30 16:48:25.000000000 +0100
@@ -39,6 +39,20 @@
#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)
#define E_CORE (E_CORE_ERROR | E_CORE_WARNING)
+#if SUHOSIN_PATCH
+#define S_MEMORY (1<<0L)
+#define S_MISC (1<<1L)
+#define S_VARS (1<<2L)
+#define S_FILES (1<<3L)
+#define S_INCLUDE (1<<4L)
+#define S_SQL (1<<5L)
+#define S_EXECUTOR (1<<6L)
+#define S_MAIL (1<<7L)
+#define S_SESSION (1<<8L)
+#define S_INTERNAL (1<<29L)
+#define S_ALL (S_MEMORY | S_VARS | S_INCLUDE | S_FILES | S_MAIL | S_SESSION | S_MISC | S_SQL | S_EXECUTOR)
+#endif
+
#endif /* ZEND_ERRORS_H */
/*
diff -Nura php-5.2.16/Zend/zend_hash.c suhosin-patch-5.2.16-0.9.7/Zend/zend_hash.c
--- php-5.2.16/Zend/zend_hash.c 2010-05-03 18:36:04.000000000 +0200
+++ suhosin-patch-5.2.16-0.9.7/Zend/zend_hash.c 2010-12-30 16:48:25.000000000 +0100
@@ -20,6 +20,7 @@
/* $Id: zend_hash.c 298914 2010-05-03 16:36:04Z felipe $ */
#include "zend.h"
+#include "zend_compile.h"
#define CONNECT_TO_BUCKET_DLLIST(element, list_head) \
(element)->pNext = (list_head); \
@@ -132,7 +133,189 @@
(p)->pDataPtr=NULL; \
}
+#if SUHOSIN_PATCH
+#ifdef ZTS
+MUTEX_T zend_hash_dprot_mx_reader;
+MUTEX_T zend_hash_dprot_mx_writer;
+unsigned int zend_hash_dprot_reader;
+#endif
+unsigned int zend_hash_dprot_counter;
+unsigned int zend_hash_dprot_curmax;
+dtor_func_t *zend_hash_dprot_table = NULL;
+
+static void zend_hash_dprot_begin_read()
+{
+#ifdef ZTS
+ tsrm_mutex_lock(zend_hash_dprot_mx_reader);
+ if ((++(zend_hash_dprot_reader)) == 1) {
+ tsrm_mutex_lock(zend_hash_dprot_mx_writer);
+ }
+ tsrm_mutex_unlock(zend_hash_dprot_mx_reader);
+#endif
+}
+
+static void zend_hash_dprot_end_read()
+{
+#ifdef ZTS
+ tsrm_mutex_lock(zend_hash_dprot_mx_reader);
+ if ((--(zend_hash_dprot_reader)) == 0) {
+ tsrm_mutex_unlock(zend_hash_dprot_mx_writer);
+ }
+ tsrm_mutex_unlock(zend_hash_dprot_mx_reader);
+#endif
+}
+
+static void zend_hash_dprot_begin_write()
+{
+#ifdef ZTS
+ tsrm_mutex_lock(zend_hash_dprot_mx_writer);
+#endif
+}
+
+static void zend_hash_dprot_end_write()
+{
+#ifdef ZTS
+ tsrm_mutex_unlock(zend_hash_dprot_mx_writer);
+#endif
+}
+
+/*ZEND_API void zend_hash_dprot_dtor()
+{
+#ifdef ZTS
+ tsrm_mutex_free(zend_hash_dprot_mx_reader);
+ tsrm_mutex_free(zend_hash_dprot_mx_writer);
+#endif
+ free(zend_hash_dprot_table);
+}*/
+
+static void zend_hash_add_destructor(dtor_func_t pDestructor)
+{
+ int left, right, mid;
+ zend_bool found = 0;
+ unsigned long value;
+
+ if (pDestructor == NULL || pDestructor == ZVAL_PTR_DTOR || pDestructor == ZVAL_INTERNAL_PTR_DTOR
+ || pDestructor == ZEND_FUNCTION_DTOR || pDestructor == ZEND_CLASS_DTOR) {
+ return;