Fix lpFileName leak in InternalCreateProcess.
authorLakshmi Priya Sekar <lasekar@microsoft.com>
Wed, 21 Oct 2015 15:57:23 +0000 (08:57 -0700)
committerLakshmi Priya Sekar <lasekar@microsoft.com>
Wed, 21 Oct 2015 18:38:50 +0000 (11:38 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/59de8a76b21c6a0b754fb1c60b094968faaca582

src/coreclr/src/pal/src/thread/process.cpp

index 862231d..6bbc96b 100644 (file)
@@ -561,7 +561,8 @@ CorUnix::InternalCreateProcess(
     int iFdErr = -1;
     
     pid_t processId;
-    char * lpFileName = (char*)InternalMalloc(pThread, MAX_LONGPATH);
+    char * lpFileName;
+    PathCharString lpFileNamePS;
     char **lppArgv = NULL;
     UINT nArg;
     int  iRet;
@@ -581,12 +582,6 @@ CorUnix::InternalCreateProcess(
                lpApplicationName);
         palError = ERROR_INVALID_PARAMETER;
         goto InternalCreateProcessExit;
-    }
-    
-    if (NULL == lpFileName)
-    {
-        palError = ERROR_NOT_ENOUGH_MEMORY;
-        goto InternalCreateProcessExit;
     } 
 
     if (0 != (dwCreationFlags & ~(CREATE_SUSPENDED|CREATE_NEW_CONSOLE)))
@@ -681,13 +676,15 @@ CorUnix::InternalCreateProcess(
         }
     }
 
+    lpFileName = lpFileNamePS.OpenStringBuffer(MAX_LONGPATH-1);
     if (!getFileName(lpApplicationName, lpCommandLine, lpFileName))
     {
         ERROR("Can't find executable!\n");
         palError = ERROR_FILE_NOT_FOUND;
         goto InternalCreateProcessExit;
     }
-
+    
+    lpFileNamePS.CloseBuffer(MAX_LONGPATH-1);
     /* check type of file */
     iRet = checkFileType(lpFileName);
 
@@ -705,8 +702,8 @@ CorUnix::InternalCreateProcess(
             if ( PAL_GetPALDirectoryA( lpFileName,
                                       (MAX_LONGPATH - (strlen(PROCESS_PELOADER_FILENAME)+1))))
             {
-                if ((strcat_s(lpFileName, sizeof(char) * MAX_LONGPATH, "/") != SAFECRT_SUCCESS) ||
-                    (strcat_s(lpFileName, sizeof(char) * MAX_LONGPATH, PROCESS_PELOADER_FILENAME) != SAFECRT_SUCCESS))
+                if ((strcat_s(lpFileName, lpFileNamePS.GetSizeOf(), "/") != SAFECRT_SUCCESS) ||
+                    (strcat_s(lpFileName, lpFileNamePS.GetSizeOf(), PROCESS_PELOADER_FILENAME) != SAFECRT_SUCCESS))
                 {
                     ERROR("strcpy_s/strcat_s failed!\n");
                     palError = ERROR_INTERNAL_ERROR;