Skip to content

Commit 98d29d2

Browse files
patrickallaertsmalyshev
authored andcommitted
Fixed #65225: PHP_BINARY incorrectly set
1 parent a3fa25e commit 98d29d2

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

main/main.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@
115115
#endif
116116
/* }}} */
117117

118+
#ifndef S_ISREG
119+
#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
120+
#endif
121+
118122
PHPAPI int (*php_register_internal_extensions_func)(TSRMLS_D) = php_register_internal_extensions;
119123

120124
#ifndef ZTS
@@ -276,13 +280,14 @@ static void php_binary_init(TSRMLS_D)
276280
if ((envpath = getenv("PATH")) != NULL) {
277281
char *search_dir, search_path[MAXPATHLEN];
278282
char *last = NULL;
283+
struct stat s;
279284

280285
path = estrdup(envpath);
281286
search_dir = php_strtok_r(path, ":", &last);
282287

283288
while (search_dir) {
284289
snprintf(search_path, MAXPATHLEN, "%s/%s", search_dir, sapi_module.executable_location);
285-
if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK)) {
290+
if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK) && VCWD_STAT(binary_location, &s) == 0 && S_ISREG(s.st_mode)) {
286291
found = 1;
287292
break;
288293
}

0 commit comments

Comments
 (0)