Skip to content

Commit 93a44f8

Browse files
hwdecmb69
authored andcommitted
Fix potential use after free in php_binary_init()
Closes GH-8791.
1 parent 229e80c commit 93a44f8

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? 2022, PHP 8.0.21
44

5+
- Core:
6+
. Fixed potential use after free in php_binary_init(). (Heiko Weber)
7+
58
- COM:
69
. Fixed bug GH-8778 (Integer arithmethic with large number variants fails).
710
(cmb)

main/main.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,15 @@ static void php_binary_init(void)
352352
{
353353
char *binary_location = NULL;
354354
#ifdef PHP_WIN32
355-
binary_location = (char *)malloc(MAXPATHLEN);
356-
if (binary_location && GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
357-
free(binary_location);
358-
PG(php_binary) = NULL;
355+
binary_location = (char *)pemalloc(MAXPATHLEN, 1);
356+
if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
357+
pefree(binary_location, 1);
358+
binary_location = NULL;
359359
}
360360
#else
361361
if (sapi_module.executable_location) {
362-
binary_location = (char *)malloc(MAXPATHLEN);
363-
if (binary_location && !strchr(sapi_module.executable_location, '/')) {
362+
binary_location = (char *)pemalloc(MAXPATHLEN, 1);
363+
if (!strchr(sapi_module.executable_location, '/')) {
364364
char *envpath, *path;
365365
int found = 0;
366366

@@ -383,11 +383,11 @@ static void php_binary_init(void)
383383
efree(path);
384384
}
385385
if (!found) {
386-
free(binary_location);
386+
pefree(binary_location, 1);
387387
binary_location = NULL;
388388
}
389389
} else if (!VCWD_REALPATH(sapi_module.executable_location, binary_location) || VCWD_ACCESS(binary_location, X_OK)) {
390-
free(binary_location);
390+
pefree(binary_location, 1);
391391
binary_location = NULL;
392392
}
393393
}

0 commit comments

Comments
 (0)