Skip to content
forked from php/php-src

Commit 2c54b72

Browse files
authored
Merge pull request #20 from php/master
sync
2 parents f8c032e + 2f119c3 commit 2c54b72

File tree

108 files changed

+6596
-6092
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+6596
-6092
lines changed

EXTENSIONS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ SINCE: 5.0
234234
-------------------------------------------------------------------------------
235235
EXTENSION: bcmath
236236
PRIMARY MAINTAINER: Andi Gutmans <[email protected]> (2000 - 2004)
237-
MAINTENANCE: Unknown
237+
MAINTENANCE: Maintained
238238
STATUS: Working
239239
-------------------------------------------------------------------------------
240240
EXTENSION: bz2

NEWS

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,12 @@ PHP NEWS
3434
. Fixed bug #81738: buffer overflow in hash_update() on long parameter.
3535
(CVE-2022-37454) (nicky at mouha dot be)
3636

37+
- Intl:
38+
. Added pattern format error infos for msgfmt_set_pattern. (David Carlier)
39+
. Added pattern format error infos for numfmt_set_pattern. (David Carlier)
40+
3741
- JSON:
38-
. Implemented RFC: json_validate()
39-
https://wiki.php.net/rfc/json_validate (Juan Morales)
42+
. Added json_validate(). (Juan Morales)
4043

4144
- Opcache:
4245
. Added start, restart and force restart time to opcache's
@@ -55,6 +58,9 @@ PHP NEWS
5558
- Posix:
5659
. Added posix_sysconf. (David Carlier)
5760

61+
- Random:
62+
. Added Randomizer::getBytesFromString(). (Joshua Rüsweg)
63+
5864
- Reflection:
5965
. Fix GH-9470 (ReflectionMethod constructor should not find private parent
6066
method). (ilutov)

TSRM/tsrm_win32.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "tsrm_win32.h"
3131
#include "zend_virtual_cwd.h"
3232
#include "win32/ioutil.h"
33+
#include "win32/winutil.h"
3334

3435
#ifdef ZTS
3536
static ts_rsrc_id win32_globals_id;
@@ -610,6 +611,22 @@ TSRM_API int pclose(FILE *stream)
610611
#define SEGMENT_PREFIX "TSRM_SHM_SEGMENT:"
611612
#define INT_MIN_AS_STRING "-2147483648"
612613

614+
615+
#define TSRM_BASE_SHM_KEY_ADDRESS 0x20000000
616+
/* Returns a number between 0x2000_0000 and 0x3fff_ffff. On Windows, key_t is int. */
617+
static key_t tsrm_choose_random_shm_key(key_t prev_key) {
618+
unsigned char buf[4];
619+
if (php_win32_get_random_bytes(buf, 4) != SUCCESS) {
620+
return prev_key + 2;
621+
}
622+
uint32_t n =
623+
((uint32_t)(buf[0]) << 24) |
624+
(((uint32_t)buf[1]) << 16) |
625+
(((uint32_t)buf[2]) << 8) |
626+
(((uint32_t)buf[3]));
627+
return (n & 0x1fffffff) + TSRM_BASE_SHM_KEY_ADDRESS;
628+
}
629+
613630
TSRM_API int shmget(key_t key, size_t size, int flags)
614631
{/*{{{*/
615632
shm_pair *shm;
@@ -621,11 +638,14 @@ TSRM_API int shmget(key_t key, size_t size, int flags)
621638
snprintf(shm_segment, sizeof(shm_segment), SEGMENT_PREFIX "%d", key);
622639

623640
shm_handle = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, shm_segment);
641+
} else {
642+
/* IPC_PRIVATE always creates a new segment even if IPC_CREAT flag isn't passed. */
643+
flags |= IPC_CREAT;
624644
}
625645

626646
if (!shm_handle) {
627647
if (flags & IPC_CREAT) {
628-
if (size > SIZE_MAX - sizeof(shm->descriptor)) {
648+
if (size == 0 || size > SIZE_MAX - sizeof(shm->descriptor)) {
629649
return -1;
630650
}
631651
size += sizeof(shm->descriptor);
@@ -649,6 +669,19 @@ TSRM_API int shmget(key_t key, size_t size, int flags)
649669
}
650670
}
651671

672+
if (key == IPC_PRIVATE) {
673+
/* This should call shm_get with a brand new key id that isn't used yet. See https://man7.org/linux/man-pages/man2/shmget.2.html
674+
* Because extensions such as shmop/sysvshm can be used in userland to attach to shared memory segments, use unpredictable high positive numbers to avoid accidentally conflicting with userland. */
675+
key = tsrm_choose_random_shm_key(TSRM_BASE_SHM_KEY_ADDRESS);
676+
for (shm_pair *ptr = TWG(shm); ptr < (TWG(shm) + TWG(shm_size)); ptr++) {
677+
if (ptr->descriptor && ptr->descriptor->shm_perm.key == key) {
678+
key = tsrm_choose_random_shm_key(key);
679+
ptr = TWG(shm);
680+
continue;
681+
}
682+
}
683+
}
684+
652685
shm = shm_get(key, NULL);
653686
if (!shm) {
654687
CloseHandle(shm_handle);

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,15 @@ PHP 8.3 UPGRADE NOTES
5858
- JSON:
5959
. Added json_validate(), which returns whether the json is valid for
6060
the given $depth and $options.
61+
RFC: https://wiki.php.net/rfc/json_validate
6162

6263
- Posix:
6364
. Added posix_sysconf call to get runtime informations.
6465

66+
- Random:
67+
. Added Randomizer::getBytesFromString().
68+
RFC: https://wiki.php.net/rfc/randomizer_additions
69+
6570
- Sockets:
6671
. Added socket_atmark to checks if the socket is OOB marked.
6772

Zend/tests/array_unpack/gh9769.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Unpacking arrays in constant expression
3+
--FILE--
4+
<?php
5+
6+
const A = [...[1, 2, 3]];
7+
const B = [...['a'=>1, 'b'=>2, 'c'=>3]];
8+
const C = [...new ArrayObject()];
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Uncaught Error: Only arrays can be unpacked in constant expression in %sgh9769.php:5
13+
Stack trace:
14+
#0 {main}
15+
thrown in %sgh9769.php on line 5

Zend/tests/gh10014.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-10014: Incorrect short-circuiting in constant expressions
3+
--FILE--
4+
<?php
5+
6+
#[Attribute(+[[][2]?->y]->y)]
7+
class y {
8+
}
9+
10+
?>
11+
--EXPECTF--
12+
Warning: Undefined array key 2 in %s on line %d
13+
14+
Warning: Attempt to read property "y" on array in %s on line %d

Zend/zend_API.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,14 @@ ZEND_API zend_result zend_fcall_info_call(zend_fcall_info *fci, zend_fcall_info_
733733
/* Zend FCC API to store and handle PHP userland functions */
734734
static zend_always_inline bool zend_fcc_equals(const zend_fcall_info_cache* a, const zend_fcall_info_cache* b)
735735
{
736+
if (UNEXPECTED((a->function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE) &&
737+
(b->function_handler->common.fn_flags & ZEND_ACC_CALL_VIA_TRAMPOLINE))) {
738+
return a->object == b->object
739+
&& a->calling_scope == b->calling_scope
740+
&& a->closure == b->closure
741+
&& zend_string_equals(a->function_handler->common.function_name, b->function_handler->common.function_name)
742+
;
743+
}
736744
return a->function_handler == b->function_handler
737745
&& a->object == b->object
738746
&& a->calling_scope == b->calling_scope

0 commit comments

Comments
 (0)