Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Fix inline zend_string using struct padding
This commit is contained in:
Ilija Tovilo 2025-01-27 19:51:47 +01:00
commit 1432a13413
No known key found for this signature in database
GPG key ID: 5050C66BFCD1015A
3 changed files with 25 additions and 15 deletions

2
NEWS
View file

@ -64,6 +64,8 @@ PHP NEWS
. Fixed bug GH-17307 (Internal closure causes JIT failure). (nielsdos) . Fixed bug GH-17307 (Internal closure causes JIT failure). (nielsdos)
. Fixed bug GH-17428 (Assertion failure ext/opcache/jit/zend_jit_ir.c:8940). . Fixed bug GH-17428 (Assertion failure ext/opcache/jit/zend_jit_ir.c:8940).
(nielsdos) (nielsdos)
. Fixed bug GH-17564 (Potential UB when reading from / writing to struct
padding). (ilutov)
- PCNTL: - PCNTL:
. Fixed pcntl_setcpuaffinity exception type from ValueError to TypeError for . Fixed pcntl_setcpuaffinity exception type from ValueError to TypeError for

View file

@ -145,6 +145,8 @@ static void preload_restart(void);
# define LOCKVAL(v) (ZCSG(v)) # define LOCKVAL(v) (ZCSG(v))
#endif #endif
#define ZCG_KEY_LEN (MAXPATHLEN * 8)
/** /**
* Clear AVX/SSE2-aligned memory. * Clear AVX/SSE2-aligned memory.
*/ */
@ -1194,7 +1196,8 @@ zend_string *accel_make_persistent_key(zend_string *str)
char *key; char *key;
int key_length; int key_length;
ZSTR_LEN(&ZCG(key)) = 0; ZEND_ASSERT(GC_REFCOUNT(ZCG(key)) == 1);
ZSTR_LEN(ZCG(key)) = 0;
/* CWD and include_path don't matter for absolute file names and streams */ /* CWD and include_path don't matter for absolute file names and streams */
if (IS_ABSOLUTE_PATH(path, path_length)) { if (IS_ABSOLUTE_PATH(path, path_length)) {
@ -1304,7 +1307,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
} }
/* Calculate key length */ /* Calculate key length */
if (UNEXPECTED((size_t)(cwd_len + path_length + include_path_len + 2) >= sizeof(ZCG(_key)))) { if (UNEXPECTED((size_t)(cwd_len + path_length + include_path_len + 2) >= ZCG_KEY_LEN)) {
return NULL; return NULL;
} }
@ -1313,7 +1316,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
* since in itself, it may include colons (which we use to separate * since in itself, it may include colons (which we use to separate
* different components of the key) * different components of the key)
*/ */
key = ZSTR_VAL(&ZCG(key)); key = ZSTR_VAL(ZCG(key));
memcpy(key, path, path_length); memcpy(key, path, path_length);
key[path_length] = ':'; key[path_length] = ':';
key_length = path_length + 1; key_length = path_length + 1;
@ -1337,7 +1340,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
parent_script_len = ZSTR_LEN(parent_script); parent_script_len = ZSTR_LEN(parent_script);
while ((--parent_script_len > 0) && !IS_SLASH(ZSTR_VAL(parent_script)[parent_script_len])); while ((--parent_script_len > 0) && !IS_SLASH(ZSTR_VAL(parent_script)[parent_script_len]));
if (UNEXPECTED((size_t)(key_length + parent_script_len + 1) >= sizeof(ZCG(_key)))) { if (UNEXPECTED((size_t)(key_length + parent_script_len + 1) >= ZCG_KEY_LEN)) {
return NULL; return NULL;
} }
key[key_length] = ':'; key[key_length] = ':';
@ -1346,11 +1349,9 @@ zend_string *accel_make_persistent_key(zend_string *str)
key_length += parent_script_len; key_length += parent_script_len;
} }
key[key_length] = '\0'; key[key_length] = '\0';
GC_SET_REFCOUNT(&ZCG(key), 1); ZSTR_H(ZCG(key)) = 0;
GC_TYPE_INFO(&ZCG(key)) = GC_STRING; ZSTR_LEN(ZCG(key)) = key_length;
ZSTR_H(&ZCG(key)) = 0; return ZCG(key);
ZSTR_LEN(&ZCG(key)) = key_length;
return &ZCG(key);
} }
/* not use_cwd */ /* not use_cwd */
@ -2025,8 +2026,8 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
ZCG(cache_opline) == EG(current_execute_data)->opline))) { ZCG(cache_opline) == EG(current_execute_data)->opline))) {
persistent_script = ZCG(cache_persistent_script); persistent_script = ZCG(cache_persistent_script);
if (ZSTR_LEN(&ZCG(key))) { if (ZSTR_LEN(ZCG(key))) {
key = &ZCG(key); key = ZCG(key);
} }
} else { } else {
@ -2579,7 +2580,7 @@ static zend_string* persistent_zend_resolve_path(zend_string *filename)
SHM_PROTECT(); SHM_PROTECT();
HANDLE_UNBLOCK_INTERRUPTIONS(); HANDLE_UNBLOCK_INTERRUPTIONS();
} else { } else {
ZSTR_LEN(&ZCG(key)) = 0; ZSTR_LEN(ZCG(key)) = 0;
} }
ZCG(cache_opline) = EG(current_execute_data) ? EG(current_execute_data)->opline : NULL; ZCG(cache_opline) = EG(current_execute_data) ? EG(current_execute_data)->opline : NULL;
ZCG(cache_persistent_script) = persistent_script; ZCG(cache_persistent_script) = persistent_script;
@ -2951,8 +2952,16 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
ZEND_TSRMLS_CACHE_UPDATE(); ZEND_TSRMLS_CACHE_UPDATE();
#endif #endif
memset(accel_globals, 0, sizeof(zend_accel_globals)); memset(accel_globals, 0, sizeof(zend_accel_globals));
accel_globals->key = zend_string_alloc(ZCG_KEY_LEN, true);
} }
#ifdef ZTS
static void accel_globals_dtor(zend_accel_globals *accel_globals)
{
zend_string_free(accel_globals->key);
}
#endif
#ifdef HAVE_HUGE_CODE_PAGES #ifdef HAVE_HUGE_CODE_PAGES
# ifndef _WIN32 # ifndef _WIN32
# include <sys/mman.h> # include <sys/mman.h>
@ -3127,7 +3136,7 @@ static void accel_move_code_to_huge_pages(void)
static int accel_startup(zend_extension *extension) static int accel_startup(zend_extension *extension)
{ {
#ifdef ZTS #ifdef ZTS
accel_globals_id = ts_allocate_id(&accel_globals_id, sizeof(zend_accel_globals), (ts_allocate_ctor) accel_globals_ctor, NULL); accel_globals_id = ts_allocate_id(&accel_globals_id, sizeof(zend_accel_globals), (ts_allocate_ctor) accel_globals_ctor, (ts_allocate_dtor) accel_globals_dtor);
#else #else
accel_globals_ctor(&accel_globals); accel_globals_ctor(&accel_globals);
#endif #endif

View file

@ -223,8 +223,7 @@ typedef struct _zend_accel_globals {
const zend_op *cache_opline; const zend_op *cache_opline;
zend_persistent_script *cache_persistent_script; zend_persistent_script *cache_persistent_script;
/* preallocated buffer for keys */ /* preallocated buffer for keys */
zend_string key; zend_string *key;
char _key[MAXPATHLEN * 8];
} zend_accel_globals; } zend_accel_globals;
typedef struct _zend_string_table { typedef struct _zend_string_table {