Skip to content

Commit 640c1c3

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix potential use after free in php_binary_init()
2 parents fa75bd0 + 5f24b85 commit 640c1c3

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

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
bool found = false;
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)