Skip to content

Commit 5f24b85

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix potential use after free in php_binary_init()
2 parents ee17296 + 93a44f8 commit 5f24b85

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PHP NEWS
99
extension code. (Sara)
1010
. Fixed bug GH-8655 (Casting an object to array does not unwrap refcount=1
1111
references). (Nicolas Grekas)
12+
. Fixed potential use after free in php_binary_init(). (Heiko Weber)
1213

1314
- COM:
1415
. Fixed bug GH-8778 (Integer arithmethic with large number variants fails).

main/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,15 @@ static void php_binary_init(void)
348348
{
349349
char *binary_location = NULL;
350350
#ifdef PHP_WIN32
351-
binary_location = (char *)malloc(MAXPATHLEN);
352-
if (binary_location && GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
353-
free(binary_location);
354-
PG(php_binary) = NULL;
351+
binary_location = (char *)pemalloc(MAXPATHLEN, 1);
352+
if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
353+
pefree(binary_location, 1);
354+
binary_location = NULL;
355355
}
356356
#else
357357
if (sapi_module.executable_location) {
358-
binary_location = (char *)malloc(MAXPATHLEN);
359-
if (binary_location && !strchr(sapi_module.executable_location, '/')) {
358+
binary_location = (char *)pemalloc(MAXPATHLEN, 1);
359+
if (!strchr(sapi_module.executable_location, '/')) {
360360
char *envpath, *path;
361361
int found = 0;
362362

@@ -379,11 +379,11 @@ static void php_binary_init(void)
379379
efree(path);
380380
}
381381
if (!found) {
382-
free(binary_location);
382+
pefree(binary_location, 1);
383383
binary_location = NULL;
384384
}
385385
} else if (!VCWD_REALPATH(sapi_module.executable_location, binary_location) || VCWD_ACCESS(binary_location, X_OK)) {
386-
free(binary_location);
386+
pefree(binary_location, 1);
387387
binary_location = NULL;
388388
}
389389
}

0 commit comments

Comments
 (0)