Skip to content

Commit 0fb3714

Browse files
committed
Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4: Fix bug #81068: Fix possible use-after-free in realpath_cache_clean()
2 parents 213063f + 99a2085 commit 0fb3714

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ PHP NEWS
55
- Core:
66
. Fixed bug #81076 (incorrect debug info on Closures with implicit binds).
77
(krakjoe)
8+
. Fixed bug #81068 (Double free in realpath_cache_clean()). (Dimitry Andric)
89

910
- Opcache:
1011
. Fixed bug #80968 (JIT segfault with return from required file). (Dmitry)

Zend/zend_virtual_cwd.c

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,25 @@ static void cwd_globals_ctor(virtual_cwd_globals *cwd_g) /* {{{ */
150150
}
151151
/* }}} */
152152

153+
static void realpath_cache_clean_helper(uint32_t max_entries, realpath_cache_bucket **cache, zend_long *cache_size)
154+
{
155+
uint32_t i;
156+
157+
for (i = 0; i < max_entries; i++) {
158+
realpath_cache_bucket *p = cache[i];
159+
while (p != NULL) {
160+
realpath_cache_bucket *r = p;
161+
p = p->next;
162+
free(r);
163+
}
164+
cache[i] = NULL;
165+
}
166+
*cache_size = 0;
167+
}
168+
153169
static void cwd_globals_dtor(virtual_cwd_globals *cwd_g) /* {{{ */
154170
{
155-
realpath_cache_clean();
171+
realpath_cache_clean_helper(sizeof(cwd_g->realpath_cache)/sizeof(cwd_g->realpath_cache[0]), cwd_g->realpath_cache, &cwd_g->realpath_cache_size);
156172
}
157173
/* }}} */
158174

@@ -340,18 +356,7 @@ static inline zend_ulong realpath_cache_key(const char *path, size_t path_len) /
340356

341357
CWD_API void realpath_cache_clean(void) /* {{{ */
342358
{
343-
uint32_t i;
344-
345-
for (i = 0; i < sizeof(CWDG(realpath_cache))/sizeof(CWDG(realpath_cache)[0]); i++) {
346-
realpath_cache_bucket *p = CWDG(realpath_cache)[i];
347-
while (p != NULL) {
348-
realpath_cache_bucket *r = p;
349-
p = p->next;
350-
free(r);
351-
}
352-
CWDG(realpath_cache)[i] = NULL;
353-
}
354-
CWDG(realpath_cache_size) = 0;
359+
realpath_cache_clean_helper(sizeof(CWDG(realpath_cache))/sizeof(CWDG(realpath_cache)[0]), CWDG(realpath_cache), &CWDG(realpath_cache_size));
355360
}
356361
/* }}} */
357362

0 commit comments

Comments
 (0)