Changeset 25558 in vbox
- Timestamp:
- Dec 22, 2009 12:45:27 PM (15 years ago)
- Location:
- trunk/src/VBox
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
r25472 r25558 141 141 #endif 142 142 143 143 144 /******************************************************************************* 144 145 * Internal Functions * … … 324 325 # ifdef RT_OS_LINUX 325 326 int cchLink = readlink("/proc/self/exe", &g_szSupLibHardenedExePath[0], sizeof(g_szSupLibHardenedExePath) - 1); 327 326 328 # elif defined(RT_OS_SOLARIS) 327 329 char szFileBuf[PATH_MAX + 1]; 328 330 sprintf(szFileBuf, "/proc/%ld/path/a.out", (long)getpid()); 329 331 int cchLink = readlink(szFileBuf, &g_szSupLibHardenedExePath[0], sizeof(g_szSupLibHardenedExePath) - 1); 330 # else /* RT_OS_FREEBSD: */ 332 333 # else /* RT_OS_FREEBSD */ 331 334 int aiName[4]; 332 size_t cbPath;333 334 335 aiName[0] = CTL_KERN; 335 336 aiName[1] = KERN_PROC; … … 337 338 aiName[3] = getpid(); 338 339 339 cbPath = sizeof(g_szSupLibHardenedExePath) - 1; 340 if(sysctl(aiName, RT_ELEMENTS(aiName), g_szSupLibHardenedExePath, &cbPath, NULL, 0) < 0) 341 supR3HardenedFatal("supR3HardenedExecDir: sysctl failed\n"); 342 343 int cchLink = strlen(g_szSupLibHardenedExePath); 340 size_t cbPath = sizeof(g_szSupLibHardenedExePath); 341 if (sysctl(aiName, RT_ELEMENTS(aiName), g_szSupLibHardenedExePath, &cbPath, NULL, 0) < 0) 342 supR3HardenedFatal("supR3HardenedExecDir: sysctl failed\n"); 343 g_szSupLibHardenedExePath[sizeof(g_szSupLibHardenedExePath) - 1] = '\0'; 344 int cchLink = strlen(g_szSupLibHardenedExePath); /* paranoid? can't we use cbPath? */ 345 344 346 # endif 345 347 if (cchLink < 0 || cchLink == sizeof(g_szSupLibHardenedExePath) - 1) -
trunk/src/VBox/Runtime/VBox/log-vbox.cpp
r25474 r25558 374 374 fclose(pFile); 375 375 } 376 376 377 # elif defined(RT_OS_FREEBSD) 377 char *pszArgFileBuf = NULL;378 /* Retrieve the required length first */ 378 379 int aiName[4]; 379 size_t cchArgs;380 381 380 aiName[0] = CTL_KERN; 382 381 aiName[1] = KERN_PROC; 383 aiName[2] = KERN_PROC_ARGS; 384 aiName[3] = -1; 385 386 /* Retrieve the required length first */ 387 cchArgs = 0; 382 aiName[2] = KERN_PROC_ARGS; /* Introduced in FreeBSD 4.0 */ 383 aiName[3] = getpid(); 384 size_t cchArgs = 0; 388 385 int rcBSD = sysctl(aiName, RT_ELEMENTS(aiName), NULL, &cchArgs, NULL, 0); 389 390 386 if (cchArgs > 0) 391 387 { 392 pszArgFileBuf = (char *)RTMemAllocZ(cchArgs + 1 /* Safety */);388 char *pszArgFileBuf = (char *)RTMemAllocZ(cchArgs + 1 /* Safety */); 393 389 if (pszArgFileBuf) 394 390 { … … 397 393 if (!rcBSD) 398 394 { 399 /* 400 * cmdline is a flattened argument list so we need 401 * to convert all \0 to blanks 402 */ 403 for(size_t i = 0; i < cchArgs - 1; i++) 395 unsigned iArg = 0; 396 size_t off = 0; 397 while (off < cchArgs) 404 398 { 405 if(pszArgFileBuf[i] == '\0') 406 pszArgFileBuf[i] = ' '; 399 size_t cchArg = strlen(&pszArgFileBuf[off]); 400 RTLogLoggerEx(pLogger, 0, ~0U, "Arg[%u]: %s\n", iArg, &pszArgFileBuf[off]); 401 402 /* advance */ 403 off += cchArg + 1; 404 iArg++; 407 405 } 408 409 RTLogLoggerEx(pLogger, 0, ~0U, "Commandline: %s\n", pszArgFileBuf);410 406 } 411 407 RTMemFree(pszArgFileBuf); 412 408 } 413 409 } 410 414 411 # elif defined(RT_OS_L4) || defined(RT_OS_OS2) || defined(RT_OS_DARWIN) 415 412 /* commandline? */ -
trunk/src/VBox/Runtime/r3/freebsd/rtProcInitExePath-freebsd.cpp
r25472 r25558 50 50 DECLHIDDEN(int) rtProcInitExePath(char *pszPath, size_t cchPath) 51 51 { 52 #ifdef KERN_PROC_PATHNAME 52 53 int aiName[4]; 53 size_t cchExePath;54 55 54 aiName[0] = CTL_KERN; 56 55 aiName[1] = KERN_PROC; 57 aiName[2] = KERN_PROC_PATHNAME; 58 aiName[3] = getpid();56 aiName[2] = KERN_PROC_PATHNAME; /* This was introduced in FreeBSD 6.0, thus the #ifdef above. */ 57 aiName[3] = -1; /* Shorthand for the current process. */ 59 58 60 cchExePath = cchPath - 1;61 if (sysctl(aiName, RT_ELEMENTS(aiName), pszPath, &cchExePath, NULL, 0) == 0)59 size_t cchExePath = cchPath; 60 if (sysctl(aiName, RT_ELEMENTS(aiName), pszPath, &cchExePath, NULL, 0) == 0) 62 61 { 62 63 63 char *pszTmp = NULL; 64 64 int rc = rtPathFromNative(&pszTmp, pszPath); 65 AssertMsgRCReturn(rc, ("rc=%Rrc psz Link=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, cchExePath, pszPath), rc);65 AssertMsgRCReturn(rc, ("rc=%Rrc pszPath=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, cchExePath, pszPath), rc); 66 66 67 67 size_t cch = strlen(pszTmp); … … 75 75 76 76 int rc = RTErrConvertFromErrno(errno); 77 AssertMsgFailed(("rc=%Rrc errno=%d cch Link=%d\n", rc, errno, cchExePath));77 AssertMsgFailed(("rc=%Rrc errno=%d cchExePath=%d\n", rc, errno, cchExePath)); 78 78 return rc; 79 80 #else 81 82 /* 83 * Read the /proc/curproc/file link, convert to native and return it. 84 */ 85 int cchLink = readlink("/proc/curproc/file", pszPath, cchPath - 1); 86 if (cchLink > 0 && (size_t)cchLink <= cchPath - 1) 87 { 88 pszPath[cchLink] = '\0'; 89 90 char *pszTmp = NULL; 91 int rc = rtPathFromNative(&pszTmp, pszPath); 92 AssertMsgRCReturn(rc, ("rc=%Rrc pszLink=\"%s\"\nhex: %.*Rhsx\n", rc, pszPath, cchLink, pszPath), rc); 93 94 size_t cch = strlen(pszTmp); 95 AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW); 96 97 memcpy(pszPath, pszTmp, cch + 1); 98 RTStrFree(pszTmp); 99 100 return VINF_SUCCESS; 101 } 102 103 int err = errno; 104 105 /* 106 * Fall back on the dynamic linker since /proc is optional. 107 */ 108 void *hExe = dlopen(NULL, 0); 109 if (hExe) 110 { 111 struct link_map const *pLinkMap = 0; 112 if (dlinfo(hExe, RTLD_DI_LINKMAP, &pLinkMap) == 0) 113 { 114 const char *pszImageName = pLinkMap->l_name; 115 if (*pszImageName == '/') /* this may not always be absolute, despite the docs. :-( */ 116 { 117 char *pszTmp = NULL; 118 int rc = rtPathFromNative(&pszTmp, pszImageName); 119 AssertMsgRCReturn(rc, ("rc=%Rrc pszImageName=\"%s\"\n", rc, pszImageName), rc); 120 121 size_t cch = strlen(pszTmp); 122 AssertReturn(cch <= cchPath, VERR_BUFFER_OVERFLOW); 123 124 memcpy(pszPath, pszTmp, cch + 1); 125 RTStrFree(pszTmp); 126 127 return VINF_SUCCESS; 128 } 129 /** @todo Try search the PATH for the file name or append the current 130 * directory, which ever makes sense... */ 131 } 132 } 133 134 int rc = RTErrConvertFromErrno(err); 135 AssertMsgFailed(("rc=%Rrc err=%d cchLink=%d hExe=%p\n", rc, err, cchLink, hExe)); 136 return rc; 137 #endif 79 138 } 80 139
Note:
See TracChangeset
for help on using the changeset viewer.