]> granicus.if.org Git - php/commitdiff
Check for binary_location allocation failure
authorSebastian Ramadan <plebbyastian@gmail.com>
Wed, 15 Nov 2017 02:24:28 +0000 (13:24 +1100)
committerkrakjoe <krakjoe@php.net>
Wed, 22 Nov 2017 04:49:04 +0000 (04:49 +0000)
main/main.c

index ce33cfb9834958d36e7384b4e73c8310eb178038..93ac6cabdddd82b8c2ca535756b23f499fd9980f 100644 (file)
@@ -259,17 +259,17 @@ static void php_disable_classes(void)
  */
 static void php_binary_init(void)
 {
-       char *binary_location;
+       char *binary_location = NULL;
 #ifdef PHP_WIN32
        binary_location = (char *)malloc(MAXPATHLEN);
-       if (GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
+       if (binary_location && GetModuleFileName(0, binary_location, MAXPATHLEN) == 0) {
                free(binary_location);
                PG(php_binary) = NULL;
        }
 #else
        if (sapi_module.executable_location) {
                binary_location = (char *)malloc(MAXPATHLEN);
-               if (!strchr(sapi_module.executable_location, '/')) {
+               if (binary_location && !strchr(sapi_module.executable_location, '/')) {
                        char *envpath, *path;
                        int found = 0;
 
@@ -299,8 +299,6 @@ static void php_binary_init(void)
                        free(binary_location);
                        binary_location = NULL;
                }
-       } else {
-               binary_location = NULL;
        }
 #endif
        PG(php_binary) = binary_location;