Changeset 80612 in vbox
- Timestamp:
- Sep 5, 2019 10:12:07 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-all/MachineLaunchVMCommonWorker.cpp
r80611 r80612 20 20 * Header Files * 21 21 *********************************************************************************************************************************/ 22 #include <iprt/process.h> 22 #include <iprt/dir.h> 23 #include <iprt/env.h> 24 #include <iprt/err.h> 25 #include <iprt/file.h> 23 26 #include <iprt/log.h> 24 27 #include <iprt/path.h> 25 #include <iprt/env.h> 26 #include <iprt/file.h> 27 #include <iprt/dir.h> 28 #include <iprt/process.h> 28 29 #include "MachineLaunchVMCommonWorker.h" 29 30 … … 88 89 NOREF(aFilename); 89 90 90 /* Get the path to the executable directory : */91 /* Get the path to the executable directory w/ trailing slash: */ 91 92 char szPath[RTPATH_MAX]; 92 RTPathAppPrivateArch(szPath, sizeof(szPath) - 1); 93 int vrc = RTPathAppPrivateArch(szPath, sizeof(szPath)); 94 AssertRCReturn(vrc, vrc); 95 vrc = RTPathEnsureTrailingSeparator(szPath, sizeof(szPath)); 96 AssertRCReturn(vrc, vrc); 93 97 size_t cbBufLeft = strlen(szPath); 94 szPath[cbBufLeft++] = RTPATH_DELIMITER;95 szPath[cbBufLeft] = '\0';96 98 char *pszNamePart = &szPath[cbBufLeft]; NOREF(pszNamePart); 97 99 cbBufLeft = sizeof(szPath) - cbBufLeft; … … 104 106 105 107 RTENV hEnv = RTENV_DEFAULT; 106 int vrc = VINF_SUCCESS;107 108 if (!aEnvironment.isEmpty()) 108 109 { … … 164 165 { 165 166 # ifdef RT_OS_DARWIN /* Avoid Launch Services confusing this with the selector by using a helper app. */ 167 168 # define OSX_APP_NAME "VirtualBoxVM" 169 # define OSX_APP_PATH_FMT "/Resources/%s.app/Contents/MacOS/VirtualBoxVM" 170 # define OSX_APP_PATH_WITH_NAME "/Resources/VirtualBoxVM.app/Contents/MacOS/VirtualBoxVM" 171 166 172 /* Modify the base path so that we don't need to use ".." below. */ 167 173 RTPathStripTrailingSlash(szPath); 168 174 RTPathStripFilename(szPath); 169 175 cbBufLeft = strlen(szPath); 170 pszNamePart = szPath + cbBufLeft;176 pszNamePart = &szPath[cbBufLeft]; Assert(!*pszNamePart); 171 177 cbBufLeft = sizeof(szPath) - cbBufLeft; 172 178 173 # define OSX_APP_NAME "VirtualBoxVM" 174 # define OSX_APP_PATH_FMT "/Resources/%s.app/Contents/MacOS/VirtualBoxVM" 175 176 Utf8Str strAppOverride = aFilename; 177 if ( strAppOverride.contains(".") 178 || strAppOverride.contains("/") 179 || strAppOverride.contains("\\") 180 || strAppOverride.contains(":")) 181 strAppOverride.setNull(); 182 Utf8Str strAppPath; 183 if (!strAppOverride.isEmpty()) 184 { 185 strAppPath = Utf8StrFmt(OSX_APP_PATH_FMT, strAppOverride.c_str()); 186 Utf8Str strFullPath(szPath); 187 strFullPath.append(strAppPath); 179 if (aFilename.isNotEmpty() && strpbrk(aFilename.c_str(), "./\\:") == NULL) 180 { 181 ssize_t cch = RTStrPrintf2(pszNamePart, cbBufLeft, OSX_APP_PATH_FMT, aFilename.c_str()); 182 AssertReturn(cch > 0, VERR_FILENAME_TOO_LONG); 188 183 /* there is a race, but people using this deserve the failure */ 189 if (!RTFileExists(s trFullPath.c_str()))190 strAppOverride.setNull();184 if (!RTFileExists(szPath)) 185 *pszNamePart = '\0'; 191 186 } 192 if (strAppOverride.isEmpty()) 193 strAppPath = Utf8StrFmt(OSX_APP_PATH_FMT, OSX_APP_NAME); 194 vrc = RTStrCopy(pszNamePart, cbBufLeft, strAppPath.c_str()); 195 AssertRCReturn(vrc, vrc); 187 if (!*pszNamePart) 188 { 189 vrc = RTStrCopy(pszNamePart, cbBufLeft, OSX_APP_PATH_WITH_NAME); 190 AssertRCReturn(vrc, vrc); 191 } 196 192 # else 197 193 static const char s_szVirtualBox_exe[] = "VirtualBoxVM" HOSTSUFF_EXE;
Note:
See TracChangeset
for help on using the changeset viewer.