Repository navigation
Expand file tree
/
Copy pathphp-8.1.34-sury-9.patch
More file actions
8877 lines (8542 loc) · 316 KB
/
Copy pathphp-8.1.34-sury-9.patch
File metadata and controls
8877 lines (8542 loc) · 316 KB
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 --git a/NEWS b/NEWS
index 9d420d2..56d073e 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,101 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+
+Backported from 8.2.34
+
+- Filter:
+ . Fixed GHSA-ch8v-r6jh-4vvr (FILTER_SANITIZE_ENCODED does not encode 0xFF).
+ (Ilia Alshanetsky)
+
+- FPM:
+ . Fixed GHSA-62xp-839h-2637 (IPv6 ACL bypass in FastCGI listen.allowed_clients
+ due to partial address comparison). (CVE-2026-91768) (Alexandre Daubois)
+
+- MySQLnd:
+ . Fixed GHSA-r6x9-5r99-36j7 (Various packet overreads in mysqlnd wire
+ protocol). (CVE-2025-1218) (Jakub Zelenka, Nora Dossche)
+
+- OpenSSL:
+ . Fixed GHSA-vvx9-73fr-5jjx (TLS hostname verification falls back to CN after
+ SAN mismatch). (CVE-2026-91769) (Jakub Zelenka)
+ . Fixed GHSA-xr7j-rvgx-xq5p (Heap buffer overflow in
+ php_openssl_matches_wildcard_name() on crafted server certificate wildcard
+ CN). (CVE-2026-91767) (Jakub Zelenka)
+
+- Phar:
+ . Fixed GHSA-j3wh-g957-2m85 (Integer overflow in phar_tar_number() allowing
+ TAR archive entry injection). (CVE-2026-6103) (Jakub Zelenka)
+
+- SOAP:
+ . Fixed GHSA-rgrp-mwpx-f6rm (Unbounded recursion in server-side
+ cleanup_xml_node()). (CVE-2026-91765) (Alexandre Daubois)
+ . Fixed GHSA-cj93-vc83-wgqv (Integer overflow to buffer overflow in SOAP HTTP
+ parsing). (CVE-2025-14181) (Nora Dossche, Jakub Zelenka)
+
+- Standard:
+ . Fixed GHSA-88hq-2827-7pg6 (Out-of-bounds read in convert.* stream filters
+ when line-break-chars contains NUL). (CVE-2026-92842) (geeknik)
+ . Fixed GHSA-fpwc-w8rq-cr92 (Cross-origin credential leak in HTTP stream
+ wrapper redirects). (CVE-2026-91766) (Alexandre Daubois, Jakub Zelenka)
+ . Fixed GHSA-7875-c8px-7q5f (Out-of-bounds read in the HTTP stream wrapper
+ when following a redirect with an empty Location header). (CVE-2026-93682)
+ (Ilia Alshanetsky, Jordi Kroon)
+
+- Windows:
+ . Fixed GHSA-9f67-6fw4-hpfp (Reserved device names are not rejected before
+ file and stream I/O). (CVE-2026-17545) (Shivam Mathur, Jakub Zelenka)
+
+Backported from 8.2.33
+
+- Date:
+ . Fixed leak on double DatePeriod::__construct() call. (ilutov)
+
+- GD:
+ . Upgrade libgd. (CVE-2026-9672) (Pierre Joye)
+
+- PGSQL:
+ . Fixed GHSA-7qpv-r5mr-78m4 (SQL injection via E'...' backslash breakout).
+ (CVE-2026-17543) (ilutov)
+
+- Phar:
+ . Fixed GHSA-vc5h-9ppw-p5f3 (Crash via recursive symlinks). (CVE-2026-7260)
+ (Jakub Zelenka)
+
+Backported from 8.2.32
+
+- OpenSSL:
+ . Fixed bug GH-22187 (Memory corruption (zend_mm_heap corrupted) in
+ openssl_encrypt with AES-WRAP-PAD). (David Carlier)
+
+Backported from 8.2.31
+
+- FPM:
+ . Fixed GHSA-7qg2-v9fj-4mwv (XSS within status endpoint). (CVE-2026-6735)
+ (Jakub Zelenka)
+
+- MBString:
+ . Fixed GHSA-wm6j-2649-pv75 (Null pointer dereference in
+ php_mb_check_encoding() via mb_ereg_search_init()). (CVE-2026-7259)
+ (vi3tL0u1s)
+
+- PDO_Firebird:
+ . Fixed GHSA-w476-322c-wpvm (SQL injection via NUL bytes in quoted strings).
+ (CVE-2025-14179) (SakiTakamachi)
+
+- SOAP:
+ . Fixed GHSA-85c2-q967-79q5 (Stale SOAP_GLOBAL(ref_map) pointer with Apache
+ Map). (CVE-2026-6722) (ilutov)
+ . Fixed GHSA-m33r-qmcv-p97q (Use-after-free after header parsing failure with
+ SOAP_PERSISTENCE_SESSION). (CVE-2026-7261) (ilutov)
+ . Fixed GHSA-hmxp-6pc4-f3vv (Broken Apache map value NULL check).
+ (CVE-2026-7262) (ilutov)
+
+- Standard:
+ . Fixed GHSA-96wq-48vp-hh57 (Signed integer overflow of char array offset).
+ (CVE-2026-7568) (TimWolla)
+ . Fixed GHSA-m8rr-4c36-8gq4 (Consistently pass unsigned char to ctype.h
+ functions). (CVE-2026-7258) (ilutov)
+
18 Dec 2025, PHP 8.1.34
- Curl:
diff --git a/Zend/tests/GHSA-wm6j-2649-pv75.phpt b/Zend/tests/GHSA-wm6j-2649-pv75.phpt
new file mode 100644
index 0000000..7257af2
--- /dev/null
+++ b/Zend/tests/GHSA-wm6j-2649-pv75.phpt
@@ -0,0 +1,22 @@
+--TEST--
+GHSA-wm6j-2649-pv75: Null pointer dereference in php_mb_check_encoding() via mb_ereg_search_init()
+--CREDITS--
+vi3tL0u1s
+--EXTENSIONS--
+mbstring
+--SKIPIF--
+<?php
+if (!function_exists('mb_regex_encoding')) die('skip No mbregex support');
+?>
+--FILE--
+<?php
+// iso-8859-11 is supported by Oniguruma but not by mbfl
+mb_regex_encoding('iso-8859-11');
+mb_ereg_search_init('x');
+?>
+--EXPECTF--
+Fatal error: Uncaught ValueError: mb_regex_encoding(): Argument #1 ($encoding) must be a valid encoding, "iso-8859-11" given in %s:%d
+Stack trace:
+#0 %s(%d): mb_regex_encoding('iso-8859-11')
+#1 {main}
+ thrown in %s on line %d
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index c0cd3c9..856e81a 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -2006,7 +2006,7 @@ ZEND_API size_t zend_dirname(char *path, size_t len)
/* Note that on Win32 CWD is per drive (heritage from CP/M).
* This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive.
*/
- if ((2 <= len) && isalpha((int)((unsigned char *)path)[0]) && (':' == path[1])) {
+ if ((2 <= len) && isalpha((unsigned char)path[0]) && (':' == path[1])) {
/* Skip over the drive spec (if any) so as not to change */
path += 2;
len_adjust += 2;
diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c
index ef5c50c..1c4abc9 100644
--- a/Zend/zend_operators.c
+++ b/Zend/zend_operators.c
@@ -2883,8 +2883,8 @@ ZEND_API int ZEND_FASTCALL zend_binary_strcasecmp_l(const char *s1, size_t len1,
len = MIN(len1, len2);
while (len--) {
- c1 = zend_tolower((int)*(unsigned char *)s1++);
- c2 = zend_tolower((int)*(unsigned char *)s2++);
+ c1 = zend_tolower((unsigned char)*(s1++));
+ c2 = zend_tolower((unsigned char)*(s2++));
if (c1 != c2) {
return c1 - c2;
}
@@ -2904,8 +2904,8 @@ ZEND_API int ZEND_FASTCALL zend_binary_strncasecmp_l(const char *s1, size_t len1
}
len = MIN(length, MIN(len1, len2));
while (len--) {
- c1 = zend_tolower((int)*(unsigned char *)s1++);
- c2 = zend_tolower((int)*(unsigned char *)s2++);
+ c1 = zend_tolower((unsigned char)*(s1++));
+ c2 = zend_tolower((unsigned char)*(s2++));
if (c1 != c2) {
return c1 - c2;
}
diff --git a/Zend/zend_virtual_cwd.c b/Zend/zend_virtual_cwd.c
index d8a9046..a0df54b 100644
--- a/Zend/zend_virtual_cwd.c
+++ b/Zend/zend_virtual_cwd.c
@@ -195,7 +195,7 @@ void virtual_cwd_main_cwd_init(uint8_t reinit) /* {{{ */
main_cwd_state.cwd_length = strlen(cwd);
#ifdef ZEND_WIN32
if (main_cwd_state.cwd_length >= 2 && cwd[1] == ':') {
- cwd[0] = toupper(cwd[0]);
+ cwd[0] = toupper((unsigned char)cwd[0]);
}
#endif
main_cwd_state.cwd = strdup(cwd);
@@ -273,7 +273,7 @@ CWD_API char *virtual_getcwd_ex(size_t *length) /* {{{ */
*length = state->cwd_length+1;
retval = (char *) emalloc(*length+1);
memcpy(retval, state->cwd, *length);
- retval[0] = toupper(retval[0]);
+ retval[0] = toupper((unsigned char)retval[0]);
retval[*length-1] = DEFAULT_SLASH;
retval[*length] = '\0';
return retval;
@@ -1029,6 +1029,19 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
fprintf(stderr,"cwd = %s path = %s\n", state->cwd, path);
#endif
+#ifdef ZEND_WIN32
+ switch (php_win32_ioutil_path_kind_a(path, path_length)) {
+ case PHP_WIN32_IOUTIL_PATH_RESERVED:
+ SET_ERRNO_FROM_WIN32_CODE(ERROR_INVALID_NAME);
+ return 1;
+ case PHP_WIN32_IOUTIL_PATH_DEVICE:
+ memcpy(resolved_path, path, path_length + 1);
+ goto verify;
+ default:
+ break;
+ }
+#endif
+
/* cwd_length can be 0 when getcwd() fails.
* This can happen under solaris when a dir does not have read permissions
* but *does* have execute permissions */
@@ -1114,7 +1127,7 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
if (resolved_path[start] == 0) {
goto verify;
}
- resolved_path[start] = toupper(resolved_path[start]);
+ resolved_path[start] = toupper((unsigned char)resolved_path[start]);
start++;
}
resolved_path[start++] = DEFAULT_SLASH;
@@ -1122,13 +1135,13 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
if (resolved_path[start] == 0) {
goto verify;
}
- resolved_path[start] = toupper(resolved_path[start]);
+ resolved_path[start] = toupper((unsigned char)resolved_path[start]);
start++;
}
resolved_path[start++] = DEFAULT_SLASH;
} else if (IS_ABSOLUTE_PATH(resolved_path, path_length)) {
/* skip DRIVE name */
- resolved_path[0] = toupper(resolved_path[0]);
+ resolved_path[0] = toupper((unsigned char)resolved_path[0]);
resolved_path[2] = DEFAULT_SLASH;
start = 3;
}
diff --git a/Zend/zend_virtual_cwd.h b/Zend/zend_virtual_cwd.h
index 728e3ba..d15c8e2 100644
--- a/Zend/zend_virtual_cwd.h
+++ b/Zend/zend_virtual_cwd.h
@@ -82,7 +82,7 @@ typedef unsigned short mode_t;
#define IS_UNC_PATH(path, len) \
(len >= 2 && IS_SLASH(path[0]) && IS_SLASH(path[1]))
#define IS_ABSOLUTE_PATH(path, len) \
- (len >= 2 && (/* is local */isalpha(path[0]) && path[1] == ':' || /* is UNC */IS_SLASH(path[0]) && IS_SLASH(path[1])))
+ (len >= 2 && (/* is local */isalpha((unsigned char)(path)[0]) && path[1] == ':' || /* is UNC */IS_SLASH(path[0]) && IS_SLASH(path[1])))
#else
#ifdef HAVE_DIRENT_H
diff --git a/ext/com_dotnet/com_extension.c b/ext/com_dotnet/com_extension.c
index 55b3c28..380ca07 100644
--- a/ext/com_dotnet/com_extension.c
+++ b/ext/com_dotnet/com_extension.c
@@ -104,11 +104,11 @@ static PHP_INI_MH(OnTypeLibFileUpdate)
}
/* Remove leading/training white spaces on search_string */
- while (isspace(*typelib_name)) {/* Ends on '\0' in worst case */
+ while (isspace((unsigned char)*typelib_name)) {/* Ends on '\0' in worst case */
typelib_name ++;
}
ptr = typelib_name + strlen(typelib_name) - 1;
- while ((ptr != typelib_name) && isspace(*ptr)) {
+ while ((ptr != typelib_name) && isspace((unsigned char)*ptr)) {
*ptr = '\0';
ptr--;
}
diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c
index 78feb74..9c5c9d6 100644
--- a/ext/date/lib/parse_date.c
+++ b/ext/date/lib/parse_date.c
@@ -509,7 +509,7 @@ static timelib_sll timelib_get_nr(const char **ptr, int max_length)
static void timelib_skip_day_suffix(const char **ptr)
{
- if (isspace(**ptr)) {
+ if (isspace((unsigned char)**ptr)) {
return;
}
if (!timelib_strncasecmp(*ptr, "nd", 2) || !timelib_strncasecmp(*ptr, "rd", 2) ||!timelib_strncasecmp(*ptr, "st", 2) || !timelib_strncasecmp(*ptr, "th", 2)) {
@@ -792,7 +792,7 @@ static timelib_long timelib_parse_tz_cor(const char **ptr, int *tz_not_found)
*tz_not_found = 1;
- while (isdigit(**ptr) || **ptr == ':') {
+ while (isdigit((unsigned char)**ptr) || **ptr == ':') {
++*ptr;
}
end = *ptr;
@@ -857,7 +857,7 @@ static timelib_long timelib_parse_tz_minutes(const char **ptr, timelib_time *t)
}
++*ptr;
- while (isdigit(**ptr)) {
+ while (isdigit((unsigned char)**ptr)) {
++*ptr;
}
@@ -25936,10 +25936,10 @@ timelib_time *timelib_strtotime(const char *s, size_t len, timelib_error_contain
in.errors->error_messages = NULL;
if (len > 0) {
- while (isspace(*s) && s < e) {
+ while (isspace((unsigned char)*s) && s < e) {
s++;
}
- while (isspace(*e) && e > s) {
+ while (isspace((unsigned char)*e) && e > s) {
e--;
}
}
diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re
index f0db34d..a2d1236 100644
--- a/ext/date/lib/parse_date.re
+++ b/ext/date/lib/parse_date.re
@@ -507,7 +507,7 @@ static timelib_sll timelib_get_nr(const char **ptr, int max_length)
static void timelib_skip_day_suffix(const char **ptr)
{
- if (isspace(**ptr)) {
+ if (isspace((unsigned char)**ptr)) {
return;
}
if (!timelib_strncasecmp(*ptr, "nd", 2) || !timelib_strncasecmp(*ptr, "rd", 2) ||!timelib_strncasecmp(*ptr, "st", 2) || !timelib_strncasecmp(*ptr, "th", 2)) {
@@ -790,7 +790,7 @@ static timelib_long timelib_parse_tz_cor(const char **ptr, int *tz_not_found)
*tz_not_found = 1;
- while (isdigit(**ptr) || **ptr == ':') {
+ while (isdigit((unsigned char)**ptr) || **ptr == ':') {
++*ptr;
}
end = *ptr;
@@ -855,7 +855,7 @@ static timelib_long timelib_parse_tz_minutes(const char **ptr, timelib_time *t)
}
++*ptr;
- while (isdigit(**ptr)) {
+ while (isdigit((unsigned char)**ptr)) {
++*ptr;
}
@@ -1938,10 +1938,10 @@ timelib_time *timelib_strtotime(const char *s, size_t len, timelib_error_contain
in.errors->error_messages = NULL;
if (len > 0) {
- while (isspace(*s) && s < e) {
+ while (isspace((unsigned char)*s) && s < e) {
s++;
}
- while (isspace(*e) && e > s) {
+ while (isspace((unsigned char)*e) && e > s) {
e--;
}
}
diff --git a/ext/date/lib/parse_iso_intervals.c b/ext/date/lib/parse_iso_intervals.c
index a467da3..113343f 100644
--- a/ext/date/lib/parse_iso_intervals.c
+++ b/ext/date/lib/parse_iso_intervals.c
@@ -948,10 +948,10 @@ void timelib_strtointerval(const char *s, size_t len,
in.errors->error_messages = NULL;
if (len > 0) {
- while (isspace(*s) && s < e) {
+ while (isspace((unsigned char)*s) && s < e) {
s++;
}
- while (isspace(*e) && e > s) {
+ while (isspace((unsigned char)*e) && e > s) {
e--;
}
}
diff --git a/ext/date/lib/parse_iso_intervals.re b/ext/date/lib/parse_iso_intervals.re
index 2a39415..0094200 100644
--- a/ext/date/lib/parse_iso_intervals.re
+++ b/ext/date/lib/parse_iso_intervals.re
@@ -343,10 +343,10 @@ void timelib_strtointerval(const char *s, size_t len,
in.errors->error_messages = NULL;
if (len > 0) {
- while (isspace(*s) && s < e) {
+ while (isspace((unsigned char)*s) && s < e) {
s++;
}
- while (isspace(*e) && e > s) {
+ while (isspace((unsigned char)*e) && e > s) {
e--;
}
}
diff --git a/ext/date/lib/timelib.c b/ext/date/lib/timelib.c
index d42c69b..9949225 100644
--- a/ext/date/lib/timelib.c
+++ b/ext/date/lib/timelib.c
@@ -126,7 +126,7 @@ void timelib_time_tz_abbr_update(timelib_time* tm, const char* tz_abbr)
TIMELIB_TIME_FREE(tm->tz_abbr);
tm->tz_abbr = timelib_strdup(tz_abbr);
for (i = 0; i < tz_abbr_len; i++) {
- tm->tz_abbr[i] = toupper(tz_abbr[i]);
+ tm->tz_abbr[i] = toupper((unsigned char)tz_abbr[i]);
}
}
diff --git a/ext/date/php_date.c b/ext/date/php_date.c
index fe58eba..4370f19 100644
--- a/ext/date/php_date.c
+++ b/ext/date/php_date.c
@@ -4283,6 +4283,23 @@ static bool date_period_initialize(timelib_time **st, timelib_time **et, timelib
return retval;
} /* }}} */
+static void date_period_reset(php_period_obj *period_obj)
+{
+ if (period_obj->start) {
+ timelib_time_dtor(period_obj->start);
+ }
+ if (period_obj->current) {
+ timelib_time_dtor(period_obj->current);
+ }
+ if (period_obj->end) {
+ timelib_time_dtor(period_obj->end);
+ }
+ if (period_obj->interval) {
+ timelib_rel_time_dtor(period_obj->interval);
+ }
+ memset(period_obj, 0, XtOffsetOf(php_period_obj, std));
+}
+
/* {{{ Creates new DatePeriod object. */
PHP_METHOD(DatePeriod, __construct)
{
@@ -4304,7 +4321,7 @@ PHP_METHOD(DatePeriod, __construct)
}
dpobj = Z_PHPPERIOD_P(ZEND_THIS);
- dpobj->current = NULL;
+ date_period_reset(dpobj);
if (isostr) {
if (!date_period_initialize(&(dpobj->start), &(dpobj->end), &(dpobj->interval), &recurrences, isostr, isostr_len)) {
@@ -4343,6 +4360,7 @@ PHP_METHOD(DatePeriod, __construct)
if (end) {
DATE_CHECK_INITIALIZED(Z_PHPDATE_P(end)->time, DateTimeInterface);
}
+ DATE_CHECK_INITIALIZED(Z_PHPINTERVAL_P(interval)->initialized, Z_OBJCE_P(interval));
/* init */
php_interval_obj *intobj = Z_PHPINTERVAL_P(interval);
diff --git a/ext/date/tests/DatePeriod_double_constructor_call.phpt b/ext/date/tests/DatePeriod_double_constructor_call.phpt
new file mode 100644
index 0000000..551d272
--- /dev/null
+++ b/ext/date/tests/DatePeriod_double_constructor_call.phpt
@@ -0,0 +1,14 @@
+--TEST--
+Double DatePeriod::__construct() call
+--FILE--
+<?php
+
+$start = new \DateTime();
+$interval = new \DateInterval('P1D');
+$period = new \DatePeriod($start, $interval, 1);
+$period->__construct($start, $interval, 1);
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
diff --git a/ext/filter/logical_filters.c b/ext/filter/logical_filters.c
index 3db0ef4..472e276 100644
--- a/ext/filter/logical_filters.c
+++ b/ext/filter/logical_filters.c
@@ -528,21 +528,21 @@ static int _php_filter_validate_domain(char * domain, size_t len, zend_long flag
}
/* First char must be alphanumeric */
- if(*s == '.' || (hostname && !isalnum((int)*(unsigned char *)s))) {
+ if(*s == '.' || (hostname && !isalnum((unsigned char)*s))) {
return 0;
}
while (s < e) {
if (*s == '.') {
/* The first and the last character of a label must be alphanumeric */
- if (*(s + 1) == '.' || (hostname && (!isalnum((int)*(unsigned char *)(s - 1)) || !isalnum((int)*(unsigned char *)(s + 1))))) {
+ if (*(s + 1) == '.' || (hostname && (!isalnum((unsigned char)s[-1]) || !isalnum((unsigned char)s[1])))) {
return 0;
}
/* Reset label length counter */
i = 1;
} else {
- if (i > 63 || (hostname && *s != '-' && !isalnum((int)*(unsigned char *)s))) {
+ if (i > 63 || (hostname && *s != '-' && !isalnum((unsigned char)*s))) {
return 0;
}
@@ -569,9 +569,9 @@ static int is_userinfo_valid(zend_string *str)
const char *valid = "-._~!$&'()*+,;=:";
const char *p = ZSTR_VAL(str);
while (p - ZSTR_VAL(str) < ZSTR_LEN(str)) {
- if (isalpha(*p) || isdigit(*p) || strchr(valid, *p)) {
+ if (isalpha((unsigned char)*p) || isdigit((unsigned char)*p) || strchr(valid, *p)) {
p++;
- } else if (*p == '%' && p - ZSTR_VAL(str) <= ZSTR_LEN(str) - 3 && isdigit(*(p+1)) && isxdigit(*(p+2))) {
+ } else if (*p == '%' && p - ZSTR_VAL(str) <= ZSTR_LEN(str) - 3 && isdigit((unsigned char)p[1]) && isxdigit((unsigned char)p[2])) {
p += 3;
} else {
return 0;
diff --git a/ext/filter/sanitizing_filters.c b/ext/filter/sanitizing_filters.c
index 7c57171..27706ae 100644
--- a/ext/filter/sanitizing_filters.c
+++ b/ext/filter/sanitizing_filters.c
@@ -67,7 +67,7 @@ static void php_filter_encode_url(zval *value, const unsigned char* chars, const
unsigned char *e = s + char_len;
zend_string *str;
- memset(tmp, 1, sizeof(tmp)-1);
+ memset(tmp, 1, sizeof(tmp));
while (s < e) {
tmp[*s++] = '\0';
diff --git a/ext/filter/tests/filter_sanitize_encoded_0xff.phpt b/ext/filter/tests/filter_sanitize_encoded_0xff.phpt
new file mode 100644
index 0000000..1ee61ab
--- /dev/null
+++ b/ext/filter/tests/filter_sanitize_encoded_0xff.phpt
@@ -0,0 +1,12 @@
+--TEST--
+FILTER_SANITIZE_ENCODED percent-encodes 0xFF
+--EXTENSIONS--
+filter
+--FILE--
+<?php
+var_dump(filter_var("\xFF", FILTER_SANITIZE_ENCODED));
+var_dump(filter_var("\xFE\xFF\x00A", FILTER_SANITIZE_ENCODED));
+?>
+--EXPECT--
+string(3) "%FF"
+string(10) "%FE%FF%00A"
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index 9253edc..9da59ea 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -499,7 +499,7 @@ ftp_raw(ftpbuf_t *ftp, const char *cmd, const size_t cmd_len, zval *return_value
array_init(return_value);
while (ftp_readline(ftp)) {
add_next_index_string(return_value, ftp->inbuf);
- if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
+ if (isdigit((unsigned char)ftp->inbuf[0]) && isdigit((unsigned char)ftp->inbuf[1]) && isdigit((unsigned char)ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
return;
}
}
@@ -841,7 +841,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv)
return 0;
}
/* parse out the IP and port */
- for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++);
+ for (ptr = ftp->inbuf; *ptr && !isdigit((unsigned char)*ptr); ptr++);
n = sscanf(ptr, "%lu,%lu,%lu,%lu,%lu,%lu", &b[0], &b[1], &b[2], &b[3], &b[4], &b[5]);
if (n != 6) {
return 0;
@@ -1144,7 +1144,7 @@ ftp_mdtm(ftpbuf_t *ftp, const char *path, const size_t path_len)
return -1;
}
/* parse out the timestamp */
- for (ptr = ftp->inbuf; *ptr && !isdigit(*ptr); ptr++);
+ for (ptr = ftp->inbuf; *ptr && !isdigit((unsigned char)*ptr); ptr++);
n = sscanf(ptr, "%4u%2u%2u%2u%2u%2u", &tm.tm_year, &tm.tm_mon, &tm.tm_mday, &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
if (n != 6) {
return -1;
@@ -1342,13 +1342,13 @@ ftp_getresp(ftpbuf_t *ftp)
}
/* Break out when the end-tag is found */
- if (isdigit(ftp->inbuf[0]) && isdigit(ftp->inbuf[1]) && isdigit(ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
+ if (isdigit((unsigned char)ftp->inbuf[0]) && isdigit((unsigned char)ftp->inbuf[1]) && isdigit((unsigned char)ftp->inbuf[2]) && ftp->inbuf[3] == ' ') {
break;
}
}
/* translate the tag */
- if (!isdigit(ftp->inbuf[0]) || !isdigit(ftp->inbuf[1]) || !isdigit(ftp->inbuf[2])) {
+ if (!isdigit((unsigned char)ftp->inbuf[0]) || !isdigit((unsigned char)ftp->inbuf[1]) || !isdigit((unsigned char)ftp->inbuf[2])) {
return 0;
}
diff --git a/ext/gd/libgd/gd_gif_in.c b/ext/gd/libgd/gd_gif_in.c
index 1f69723..e055f90 100644
--- a/ext/gd/libgd/gd_gif_in.c
+++ b/ext/gd/libgd/gd_gif_in.c
@@ -450,7 +450,7 @@ LWZReadByte_(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, i
sd->table[1][i] = i;
}
for (; i < (1<<MAX_LWZ_BITS); ++i)
- sd->table[0][i] = sd->table[1][0] = 0;
+ sd->table[0][i] = sd->table[1][i] = 0;
sd->sp = sd->stack;
@@ -494,6 +494,8 @@ LWZReadByte_(gdIOCtx *fd, LZW_STATIC_DATA *sd, char flag, int input_code_size, i
if (count != 0)
return -2;
+
+ return -2;
}
incode = code;
@@ -560,7 +562,7 @@ ReadImage(gdImagePtr im, gdIOCtx *fd, int len, int height, unsigned char (*cmap)
int v;
int xpos = 0, ypos = 0, pass = 0;
int i;
- LZW_STATIC_DATA sd;
+ LZW_STATIC_DATA sd = {0};
/*
diff --git a/ext/gd/libgd/gd_xbm.c b/ext/gd/libgd/gd_xbm.c
index 3c655a2..8efb34f 100644
--- a/ext/gd/libgd/gd_xbm.c
+++ b/ext/gd/libgd/gd_xbm.c
@@ -191,7 +191,7 @@ void gdImageXbmCtx(gdImagePtr image, char* file_name, int fg, gdIOCtx * out)
} else {
for (i=0; i<l; i++) {
/* only in C-locale isalnum() would work */
- if (!isupper(name[i]) && !islower(name[i]) && !isdigit(name[i])) {
+ if (!isupper((unsigned char)name[i]) && !islower((unsigned char)name[i]) && !isdigit((unsigned char)name[i])) {
name[i] = '_';
}
}
diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c
index 5c45e21..74fa59d 100644
--- a/ext/imap/php_imap.c
+++ b/ext/imap/php_imap.c
@@ -2316,7 +2316,7 @@ PHP_FUNCTION(imap_utf8)
#define SPECIAL(c) ((c) <= 0x1f || (c) >= 0x7f)
/* validate a modified-base64 character */
-#define B64CHAR(c) (isalnum(c) || (c) == '+' || (c) == ',')
+#define B64CHAR(c) (isalnum((unsigned char)(c)) || (c) == '+' || (c) == ',')
/* map the low 64 bits of `n' to the modified-base64 characters */
#define B64(n) ("ABCDEFGHIJKLMNOPQRSTUVWXYZ" \
diff --git a/ext/intl/locale/locale_methods.c b/ext/intl/locale/locale_methods.c
index 159b3ea..adca3ed 100644
--- a/ext/intl/locale/locale_methods.c
+++ b/ext/intl/locale/locale_methods.c
@@ -1135,7 +1135,7 @@ static int strToMatch(const char* str ,char *retstr)
if( *str == '-' ){
*retstr = '_';
} else {
- *retstr = tolower(*str);
+ *retstr = tolower((unsigned char)*str);
}
str++;
retstr++;
diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c
index 238d74e..265356a 100644
--- a/ext/mbstring/mbstring.c
+++ b/ext/mbstring/mbstring.c
@@ -626,7 +626,7 @@ static char *php_mb_rfc1867_getword(const zend_encoding *encoding, char **line,
static char *php_mb_rfc1867_getword_conf(const zend_encoding *encoding, char *str) /* {{{ */
{
- while (*str && isspace(*(unsigned char *)str)) {
+ while (*str && isspace((unsigned char)*str)) {
++str;
}
@@ -642,7 +642,7 @@ static char *php_mb_rfc1867_getword_conf(const zend_encoding *encoding, char *st
} else {
char *strend = str;
- while (*strend && !isspace(*(unsigned char *)strend)) {
+ while (*strend && !isspace((unsigned char)*strend)) {
++strend;
}
return php_mb_rfc1867_substring_conf(encoding, str, strend - str, 0);
diff --git a/ext/mbstring/php_mbregex.c b/ext/mbstring/php_mbregex.c
index 06f65f5..5342de2 100644
--- a/ext/mbstring/php_mbregex.c
+++ b/ext/mbstring/php_mbregex.c
@@ -409,8 +409,13 @@ int php_mb_regex_set_mbctype(const char *encname)
if (mbctype == ONIG_ENCODING_UNDEF) {
return FAILURE;
}
+ const mbfl_encoding *mbfl_enc = mbfl_name2encoding(encname);
+ if (mbfl_enc == NULL) {
+ /* Encoding supported by Oniguruma but not by mbfl */
+ return FAILURE;
+ }
MBREX(current_mbctype) = mbctype;
- MBREX(current_mbctype_mbfl_encoding) = mbfl_name2encoding(encname);
+ MBREX(current_mbctype_mbfl_encoding) = mbfl_enc;
return SUCCESS;
}
/* }}} */
@@ -779,7 +784,7 @@ static inline void mb_regex_substitute(
continue;
}
if (name_end[0] == delim) break;
- if (maybe_num && !isdigit(name_end[0])) maybe_num = 0;
+ if (maybe_num && !isdigit((unsigned char)name_end[0])) maybe_num = 0;
name_end++;
}
p = name_end + 1;
diff --git a/ext/mysqli/tests/fake_server.inc b/ext/mysqli/tests/fake_server.inc
index d6afbb0..ff49ae8 100644
--- a/ext/mysqli/tests/fake_server.inc
+++ b/ext/mysqli/tests/fake_server.inc
@@ -168,11 +168,11 @@ class my_mysqli_fake_packet_generator
return new my_mysqli_fake_packet_item(null, $packed_value, $is_hex);
}
- public function server_ok(): my_mysqli_fake_packet
+ public function server_ok($number = "02"): my_mysqli_fake_packet
{
$packet = new my_mysqli_fake_packet();
$packet->packet_length = "070000";
- $packet->packet_number = "02";
+ $packet->packet_number = $number;
$packet->header = "00"; // OK
$packet->affected_rows = "00";
$packet->last_insert_id = "00";
@@ -181,6 +181,17 @@ class my_mysqli_fake_packet_generator
return $packet;
}
+ public function server_eof(): my_mysqli_fake_packet
+ {
+ $packet = new my_mysqli_fake_packet();
+ $packet->packet_length = "050000";
+ $packet->packet_number = "01";
+ $packet->header = "fe"; // EOF
+ $packet->warning_count = "0000";
+ $packet->server_status = "0200";
+ return $packet;
+ }
+
public function server_greetings(): my_mysqli_fake_packet
{
$packet = new my_mysqli_fake_packet();
@@ -204,6 +215,25 @@ class my_mysqli_fake_packet_generator
return $packet;
}
+ public function server_greetings_sha256(): my_mysqli_fake_packet
+ {
+ $packet = $this->server_greetings();
+ // 6 bytes shorter than the default mysql_native_password greeting
+ $packet->packet_length = "520000";
+ $packet->mariadb_extended_server_capabilities_auth_plugin =
+ self::create_packet_item('sha256_password');
+
+ return $packet;
+ }
+ public function server_greetings_caching_sha2(): my_mysqli_fake_packet
+ {
+ $packet = $this->server_greetings();
+ // same length as the default mysql_native_password so the length stays
+ $packet->mariadb_extended_server_capabilities_auth_plugin =
+ self::create_packet_item('caching_sha2_password');
+
+ return $packet;
+ }
public function server_tabular_query_response(): array
{
$qr1 = new my_mysqli_fake_packet();
@@ -246,7 +276,6 @@ class my_mysqli_fake_packet_generator
$qr1->packet_number = "01";
$qr1->field_count = "00"; // UPSERT
$qr1->affected_rows = "00";
- $qr1->affected_rows = "00";
$qr1->last_insert_id = "00";
$qr1->server_status = "0000";
$qr1->warning_count = "0000";
@@ -257,6 +286,21 @@ class my_mysqli_fake_packet_generator
return [$qr1];
}
+ public function server_upsert_result_response(): my_mysqli_fake_packet
+ {
+ $ur = new my_mysqli_fake_packet();
+ $ur->packet_length = "300000";
+ $ur->packet_number = "01";
+ $ur->field_count = "00"; // UPSERT
+ $ur->affected_rows = "00";
+ $ur->last_insert_id = "00";
+ $ur->server_status = "0002";
+ $ur->warning_count = "0000";
+ $ur->payload = "28526f7773206d6174636865643a203120204368616e6765643a203020205761726e696e67733a2030";
+
+ return $ur;
+ }
+
public function server_stmt_prepare_response_start($num_field): my_mysqli_fake_packet
{
$pr1 = new my_mysqli_fake_packet();
@@ -712,6 +756,44 @@ function my_mysqli_test_stmt_response_row_over_read_string(my_mysqli_fake_server
$conn->read(65536);
}
+function my_mysqli_test_stmt_response_row_short_length(
+ my_mysqli_fake_server_conn $conn,
+ string $field_name
+): void {
+ $rh = $conn->packet_generator->server_stmt_execute_data_response($field_name);
+
+ // The length does not cover the fixed offsets that the field type reads
+ $rh[4]->packet_length = '090000';
+ $rh[4]->row_field2 = '01de';
+
+ $conn->send_server_greetings();
+ $conn->read();
+ $conn->send_server_ok();
+ $conn->read();
+ $conn->send_server_stmt_prepare_data_response($field_name);
+ $conn->read();
+ $conn->send(
+ $conn->packets_to_bytes($rh),
+ "Malicious Stmt Response for data $field_name [length too short]"
+ );
+ $conn->read(65536);
+}
+
+function my_mysqli_test_stmt_response_row_short_length_date(my_mysqli_fake_server_conn $conn): void
+{
+ my_mysqli_test_stmt_response_row_short_length($conn, 'datval');
+}
+
+function my_mysqli_test_stmt_response_row_short_length_time(my_mysqli_fake_server_conn $conn): void
+{
+ my_mysqli_test_stmt_response_row_short_length($conn, 'timval');
+}
+
+function my_mysqli_test_stmt_response_row_short_length_datetime(my_mysqli_fake_server_conn $conn): void
+{
+ my_mysqli_test_stmt_response_row_short_length($conn, 'dtival');
+}
+
function my_mysqli_test_stmt_response_row_over_read_two_fields(
my_mysqli_fake_server_conn $conn,
string $field_name,
@@ -805,6 +887,114 @@ function my_mysqli_test_query_response_row_length_overflow(my_mysqli_fake_server
$conn->read(65536);
}
+function my_mysqli_test_query_response_row_field_len(my_mysqli_fake_server_conn $conn): void
+{
+ $rh = $conn->packet_generator->server_query_execute_data_response('strval');
+
+ // 2-byte length prefix (0xfc) with the packet ending right after it, so
+ // decoding the length itself would read past the end of the packet
+ $rh[4]->row_field2 = 'fc';
+ $rh[4]->packet_length = '060000';
+
+ $conn->send_server_greetings();
+ $conn->read();
+ $conn->send_server_ok();
+ $conn->read();
+ $conn->send($conn->packets_to_bytes($rh), "Malicious Query Response for data strval field [field length over-read]");
+ $conn->read(65536);
+}
+
+function my_mysqli_test_query_response_row(my_mysqli_fake_server_conn $conn, string $packet_length,
+ string $row_field2, string $message): void
+{
+ $rh = $conn->packet_generator->server_query_execute_data_response('strval');
+ $rh[4]->packet_length = $packet_length;
+ $rh[4]->row_field2 = $row_field2;
+
+ $conn->send_server_greetings();
+ $conn->read();
+ $conn->send_server_ok();
+ $conn->read();
+ $conn->send($conn->packets_to_bytes($rh), $message);
+ $conn->read(65536);
+}
+
+function my_mysqli_test_query_response_row_eof_short(my_mysqli_fake_server_conn $conn): void
+{
+ $rh = $conn->packet_generator->server_query_execute_data_response('strval');
+ // EOF row packet that has no space for the warnings and the status
+ $rh[5]->packet_length = '030000';
+ $rh[5]->server_status = '';
+
+ $conn->send_server_greetings();
+ $conn->read();
+ $conn->send_server_ok();
+ $conn->read();
+ $conn->send($conn->packets_to_bytes($rh), "Malicious Query Response [short EOF row packet]");
+ $conn->read(65536);
+}
+
+function my_mysqli_test_query_response_row_field_null(my_mysqli_fake_server_conn $conn): void
+{
+ // NULL field, which is encoded as a single 0xfb byte
+ my_mysqli_test_query_response_row($conn, "060000", "fb", "Query Response for data strval field [NULL]");
+}
+
+function my_mysqli_test_query_response_row_field_len_2_bytes(my_mysqli_fake_server_conn $conn): void
+{
+ // field length encoded on 2 bytes
+ my_mysqli_test_query_response_row($conn, "0c0000", "fc040074657374",
+ "Query Response for data strval field [length on 2 bytes]");
+}
+
+function my_mysqli_test_query_rset_header_field_over_read(my_mysqli_fake_server_conn $conn): void
+{
+ $rh = $conn->packet_generator->server_query_execute_data_response('strval');
+
+ $rh[0]->num_fields = "fd";
+
+ $conn->send_server_greetings();
+ $conn->read();
+ $conn->send_server_ok();
+ $conn->read();
+ $conn->send($conn->packets_to_bytes($rh), "Malicious Query Response for data strval field [length overflow]");
+ $conn->read(65536);
+}
+
+function my_mysqli_test_upsert_rset_header_affected_rows_over_read(my_mysqli_fake_server_conn $conn): void
+{
+ $ur = $conn->packet_generator->server_upsert_result_response();
+
+ $ur->packet_length = "020000";
+ $ur->affected_rows = "fd";
+ $ur->last_insert_id = "";
+ $ur->server_status = "";
+ $ur->warning_count = "";
+ $ur->payload = "";
+
+ $conn->send_server_greetings();
+ $conn->read();
+ $conn->send_server_ok();
+ $conn->read();
+ $conn->send($ur->to_bytes(), "Malicious Upsert Response [affected rows overflow]");
+ $conn->read(65536);
+}
+
+function my_mysqli_test_upsert_rset_header_packet_len_over_read(my_mysqli_fake_server_conn $conn): void
+{
+ $ur = $conn->packet_generator->server_upsert_result_response();
+
+ $ur->affected_rows = "fd";
+
+ $conn->send_server_greetings();
+ $conn->read();
+ $conn->send_server_ok();
+ $conn->read();
+ $conn->send($ur->to_bytes(), "Malicious Upsert Response [affected rows overflow]");
+ $conn->read(65536);
+}
+
+
function my_mysqli_test_query_response_row_read_two_fields(my_mysqli_fake_server_conn $conn): void
{
$conn->send_server_greetings();
@@ -818,7 +1008,401 @@ function my_mysqli_test_query_response_row_read_two_fields(my_mysqli_fake_server
}
}
-function run_fake_server(string $test_function, int|string $port = 0): int
+function my_mysqli_test_auth_affected_rows_over_read(my_mysqli_fake_server_conn $conn): void
+{
+ $p = $conn->packet_generator->server_ok();
+ $p->packet_length = "020000";
+ $p->affected_rows = "fe";
+ $p->last_insert_id = "";
+ $p->server_status = "";
+ $p->warning_count = "";
+
+ $conn->send_server_greetings();
+ $conn->read();
+ $conn->send($p->to_bytes(), "Malicious OK Auth Response");
+ $conn->read();
+}
+
+function my_mysqli_test_auth_last_insert_id_over_read(my_mysqli_fake_server_conn $conn): void
+{
+ $p = $conn->packet_generator->server_ok();
+ $p->packet_length = "030000";
+ $p->last_insert_id = "fd";
+ $p->server_status = "";
+ $p->warning_count = "";
+
+ $conn->send_server_greetings();
+ $conn->read();
+ $conn->send($p->to_bytes(), "Malicious OK Auth Response");
+ $conn->read();
+}
+
+function my_mysqli_test_auth_warning_count_over_read(my_mysqli_fake_server_conn $conn): void
+{
+ $p = $conn->packet_generator->server_ok();
+ $p->packet_length = "060000";