Skip to content

Commit 62b3441

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix inline zend_string using struct padding
2 parents f926c5c + 1432a13 commit 62b3441

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

ext/opcache/ZendAccelerator.c

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ static void preload_restart(void);
146146
# define LOCKVAL(v) (ZCSG(v))
147147
#endif
148148

149+
#define ZCG_KEY_LEN (MAXPATHLEN * 8)
150+
149151
/**
150152
* Clear AVX/SSE2-aligned memory.
151153
*/
@@ -1195,7 +1197,8 @@ zend_string *accel_make_persistent_key(zend_string *str)
11951197
char *key;
11961198
int key_length;
11971199

1198-
ZSTR_LEN(&ZCG(key)) = 0;
1200+
ZEND_ASSERT(GC_REFCOUNT(ZCG(key)) == 1);
1201+
ZSTR_LEN(ZCG(key)) = 0;
11991202

12001203
/* CWD and include_path don't matter for absolute file names and streams */
12011204
if (IS_ABSOLUTE_PATH(path, path_length)) {
@@ -1305,7 +1308,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
13051308
}
13061309

13071310
/* Calculate key length */
1308-
if (UNEXPECTED((size_t)(cwd_len + path_length + include_path_len + 2) >= sizeof(ZCG(_key)))) {
1311+
if (UNEXPECTED((size_t)(cwd_len + path_length + include_path_len + 2) >= ZCG_KEY_LEN)) {
13091312
return NULL;
13101313
}
13111314

@@ -1314,7 +1317,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
13141317
* since in itself, it may include colons (which we use to separate
13151318
* different components of the key)
13161319
*/
1317-
key = ZSTR_VAL(&ZCG(key));
1320+
key = ZSTR_VAL(ZCG(key));
13181321
memcpy(key, path, path_length);
13191322
key[path_length] = ':';
13201323
key_length = path_length + 1;
@@ -1338,7 +1341,7 @@ zend_string *accel_make_persistent_key(zend_string *str)
13381341
parent_script_len = ZSTR_LEN(parent_script);
13391342
while ((--parent_script_len > 0) && !IS_SLASH(ZSTR_VAL(parent_script)[parent_script_len]));
13401343

1341-
if (UNEXPECTED((size_t)(key_length + parent_script_len + 1) >= sizeof(ZCG(_key)))) {
1344+
if (UNEXPECTED((size_t)(key_length + parent_script_len + 1) >= ZCG_KEY_LEN)) {
13421345
return NULL;
13431346
}
13441347
key[key_length] = ':';
@@ -1347,11 +1350,9 @@ zend_string *accel_make_persistent_key(zend_string *str)
13471350
key_length += parent_script_len;
13481351
}
13491352
key[key_length] = '\0';
1350-
GC_SET_REFCOUNT(&ZCG(key), 1);
1351-
GC_TYPE_INFO(&ZCG(key)) = GC_STRING;
1352-
ZSTR_H(&ZCG(key)) = 0;
1353-
ZSTR_LEN(&ZCG(key)) = key_length;
1354-
return &ZCG(key);
1353+
ZSTR_H(ZCG(key)) = 0;
1354+
ZSTR_LEN(ZCG(key)) = key_length;
1355+
return ZCG(key);
13551356
}
13561357

13571358
/* not use_cwd */
@@ -2026,8 +2027,8 @@ zend_op_array *persistent_compile_file(zend_file_handle *file_handle, int type)
20262027
ZCG(cache_opline) == EG(current_execute_data)->opline))) {
20272028

20282029
persistent_script = ZCG(cache_persistent_script);
2029-
if (ZSTR_LEN(&ZCG(key))) {
2030-
key = &ZCG(key);
2030+
if (ZSTR_LEN(ZCG(key))) {
2031+
key = ZCG(key);
20312032
}
20322033

20332034
} else {
@@ -2580,7 +2581,7 @@ static zend_string* persistent_zend_resolve_path(zend_string *filename)
25802581
SHM_PROTECT();
25812582
HANDLE_UNBLOCK_INTERRUPTIONS();
25822583
} else {
2583-
ZSTR_LEN(&ZCG(key)) = 0;
2584+
ZSTR_LEN(ZCG(key)) = 0;
25842585
}
25852586
ZCG(cache_opline) = EG(current_execute_data) ? EG(current_execute_data)->opline : NULL;
25862587
ZCG(cache_persistent_script) = persistent_script;
@@ -2952,7 +2953,15 @@ static void accel_globals_ctor(zend_accel_globals *accel_globals)
29522953
ZEND_TSRMLS_CACHE_UPDATE();
29532954
#endif
29542955
memset(accel_globals, 0, sizeof(zend_accel_globals));
2956+
accel_globals->key = zend_string_alloc(ZCG_KEY_LEN, true);
2957+
}
2958+
2959+
#ifdef ZTS
2960+
static void accel_globals_dtor(zend_accel_globals *accel_globals)
2961+
{
2962+
zend_string_free(accel_globals->key);
29552963
}
2964+
#endif
29562965

29572966
#ifdef HAVE_HUGE_CODE_PAGES
29582967
# ifndef _WIN32
@@ -3128,7 +3137,7 @@ static void accel_move_code_to_huge_pages(void)
31283137
static int accel_startup(zend_extension *extension)
31293138
{
31303139
#ifdef ZTS
3131-
accel_globals_id = ts_allocate_id(&accel_globals_id, sizeof(zend_accel_globals), (ts_allocate_ctor) accel_globals_ctor, NULL);
3140+
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);
31323141
#else
31333142
accel_globals_ctor(&accel_globals);
31343143
#endif

ext/opcache/ZendAccelerator.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ typedef struct _zend_accel_globals {
224224
const zend_op *cache_opline;
225225
zend_persistent_script *cache_persistent_script;
226226
/* preallocated buffer for keys */
227-
zend_string key;
228-
char _key[MAXPATHLEN * 8];
227+
zend_string *key;
229228
} zend_accel_globals;
230229

231230
typedef struct _zend_string_table {

0 commit comments

Comments
 (0)