]> granicus.if.org Git - php/commitdiff
Fixed #65225: PHP_BINARY incorrectly set
authorPatrick Allaert <pa@ez.no>
Tue, 9 Jul 2013 13:05:10 +0000 (15:05 +0200)
committerStanislav Malyshev <stas@php.net>
Sun, 18 Aug 2013 21:18:33 +0000 (14:18 -0700)
main/main.c

index b639ab165836ba4723c449cdf9508ed78eaf256a..1fd82c8398203b885b1dad83e99848558649f0bb 100644 (file)
 #endif
 /* }}} */
 
+#ifndef S_ISREG
+#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG)
+#endif
+
 PHPAPI int (*php_register_internal_extensions_func)(TSRMLS_D) = php_register_internal_extensions;
 
 #ifndef ZTS
@@ -276,13 +280,14 @@ static void php_binary_init(TSRMLS_D)
                        if ((envpath = getenv("PATH")) != NULL) {
                                char *search_dir, search_path[MAXPATHLEN];
                                char *last = NULL;
+                               struct stat s;
 
                                path = estrdup(envpath);
                                search_dir = php_strtok_r(path, ":", &last);
 
                                while (search_dir) {
                                        snprintf(search_path, MAXPATHLEN, "%s/%s", search_dir, sapi_module.executable_location);
-                                       if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK)) {
+                                       if (VCWD_REALPATH(search_path, binary_location) && !VCWD_ACCESS(binary_location, X_OK) && VCWD_STAT(binary_location, &s) == 0 && S_ISREG(s.st_mode)) {
                                                found = 1;
                                                break;
                                        }