- Timestamp:
- Oct 6, 2018 9:03:45 PM (6 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/ldr/ldrLX.cpp
r74645 r74646 213 213 /* Verify the loader section. */ 214 214 offEnd = Hdr.e32_objtab + Hdr.e32_ldrsize; 215 if (Hdr.e32_objtab < sizeof(Hdr)) 216 return VERR_LDRLX_BAD_LOADER_SECTION; 215 if (Hdr.e32_objtab < sizeof(Hdr) && Hdr.e32_objcnt) 216 return RTErrInfoSetF(pErrInfo, VERR_LDRLX_BAD_LOADER_SECTION, 217 "Object table is inside the header: %#x", Hdr.e32_objtab); 217 218 off = Hdr.e32_objtab + sizeof(struct o32_obj) * Hdr.e32_objcnt; 218 219 if (off > offEnd) 219 return VERR_LDRLX_BAD_LOADER_SECTION; 220 return RTErrInfoSetF(pErrInfo, VERR_LDRLX_BAD_LOADER_SECTION, 221 "Object table spans beyond the executable: e32_objcnt=%u", Hdr.e32_objcnt); 220 222 if ( Hdr.e32_objmap 221 223 && (Hdr.e32_objmap < off || Hdr.e32_objmap > offEnd)) 222 return VERR_LDRLX_BAD_LOADER_SECTION; 224 return RTErrInfoSetF(pErrInfo, VERR_LDRLX_BAD_LOADER_SECTION, 225 "Bad object page map table offset: %#x", Hdr.e32_objmap); 223 226 if ( Hdr.e32_rsrccnt 224 227 && ( Hdr.e32_rsrctab < off 225 228 || Hdr.e32_rsrctab > offEnd 226 229 || Hdr.e32_rsrctab + sizeof(struct rsrc32) * Hdr.e32_rsrccnt > offEnd)) 227 return VERR_LDRLX_BAD_LOADER_SECTION; 230 return RTErrInfoSetF(pErrInfo, VERR_LDRLX_BAD_LOADER_SECTION, 231 "Resource table is out of bounds: %#x entries at %#x", Hdr.e32_rsrccnt, Hdr.e32_rsrctab); 228 232 if ( Hdr.e32_restab 229 233 && (Hdr.e32_restab < off || Hdr.e32_restab > offEnd - 2)) … … 510 514 KLDRMODLX_ASSERT(!pModLX->pvMapping); 511 515 512 int rc = VINF_SUCCESS;513 if (pModLX->Core.pReader)514 {515 rc = pModLX->Core.pReader->pfnDestroy(pModLX->Core.pReader);516 pModLX->Core.pReader = NULL;517 }518 516 if (pModLX->pbNonResNameTab) 519 517 { … … 526 524 pModLX->pbFixupSection = NULL; 527 525 } 528 pModLX->Core.u32Magic = 0; 529 pModLX->Core.pOps = NULL; 530 RTMemFree(pModLX); 531 return rc; 526 return VINF_SUCCESS; 532 527 } 533 528 -
trunk/src/VBox/Runtime/common/ldr/ldrMachO.cpp
r74643 r74646 199 199 200 200 /** The image UUID, all zeros if not found. */ 201 uint 32_tabImageUuid[16];201 uint8_t abImageUuid[16]; 202 202 203 203 /** The RVA of the Global Offset Table. */ … … 230 230 static int kldrModMachOPreParseLoadCommands(uint8_t *pbLoadCommands, const mach_header_32_t *pHdr, PRTLDRREADER pRdr, RTFOFF offImage, 231 231 uint32_t fOpenFlags, uint32_t *pcSegments, uint32_t *pcSections, uint32_t *pcbStringPool, 232 bool *pfCanLoad, PRTLDRADDR pLinkAddress, uint8_t *puEffFileType );232 bool *pfCanLoad, PRTLDRADDR pLinkAddress, uint8_t *puEffFileType, PRTERRINFO pErrInfo); 233 233 static int kldrModMachOParseLoadCommands(PKLDRMODMACHO pThis, char *pbStringPool, uint32_t cbStringPool); 234 234 … … 344 344 if (RT_SUCCESS(rc)) 345 345 rc = kldrModMachOPreParseLoadCommands(pbLoadCommands, &s.Hdr32, pRdr, offImage, fOpenFlags, 346 &cSegments, &cSections, &cbStringPool, &fCanLoad, &LinkAddress, &uEffFileType); 346 &cSegments, &cSections, &cbStringPool, &fCanLoad, &LinkAddress, &uEffFileType, 347 pErrInfo); 347 348 if (RT_FAILURE(rc)) 348 349 { … … 510 511 * @param fOpenFlags RTLDR_O_XXX. 511 512 * @param pcSegments Where to store the segment count. 512 * @param pcSe gments Where to store the section count.513 * @param pcSections Where to store the section count. 513 514 * @param pcbStringPool Where to store the string pool size. 514 515 * @param pfCanLoad Where to store the can-load-image indicator. … … 516 517 * lowest segment address). 517 518 * @param puEffFileType Where to store the effective file type. 519 * @param pErrInfo Where to return additional error info. Optional. 518 520 */ 519 521 static int kldrModMachOPreParseLoadCommands(uint8_t *pbLoadCommands, const mach_header_32_t *pHdr, PRTLDRREADER pRdr, 520 522 RTFOFF offImage, uint32_t fOpenFlags, uint32_t *pcSegments, uint32_t *pcSections, 521 523 uint32_t *pcbStringPool, bool *pfCanLoad, PRTLDRADDR pLinkAddress, 522 uint8_t *puEffFileType )524 uint8_t *puEffFileType, PRTERRINFO pErrInfo) 523 525 { 524 526 union … … 598 600 599 601 /* Validation code shared with the 64-bit variant. */ 600 602 #define VALIDATE_AND_ADD_SEGMENT(a_cBits) \ 601 603 do { \ 602 604 bool fSkipSeg = !strcmp(pSrcSeg->segname, "__DWARF") /* Note: Not for non-object files. */ \ … … 1005 1007 /** @todo valid command size. */ 1006 1008 if (!(fOpenFlags & RTLDR_O_FOR_DEBUG)) 1007 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_UNSUPPORTED_LOAD_COMMAND); 1009 KLDRMODMACHO_FAILED_RETURN(RTErrInfoSetF(pErrInfo, VERR_LDRMACHO_UNSUPPORTED_LOAD_COMMAND, 1010 "cmd=%#x", u.pLoadCmd->cmd)); 1008 1011 *pfCanLoad = false; 1009 1012 break; … … 1023 1026 case LC_PREBIND_CKSUM: 1024 1027 case LC_SYMSEG: 1025 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_UNSUPPORTED_LOAD_COMMAND); 1028 KLDRMODMACHO_FAILED_RETURN(RTErrInfoSetF(pErrInfo, VERR_LDRMACHO_UNSUPPORTED_LOAD_COMMAND, 1029 "cmd=%#x", u.pLoadCmd->cmd)); 1026 1030 1027 1031 default: 1028 KLDRMODMACHO_FAILED_RETURN(VERR_LDRMACHO_UNKNOWN_LOAD_COMMAND); 1032 KLDRMODMACHO_FAILED_RETURN(RTErrInfoSetF(pErrInfo, VERR_LDRMACHO_UNKNOWN_LOAD_COMMAND, 1033 "cmd=%#x", u.pLoadCmd->cmd)); 1029 1034 } 1030 1035 } … … 1418 1423 { 1419 1424 PKLDRMODMACHO pThis = RT_FROM_MEMBER(pMod, KLDRMODMACHO, Core); 1420 int rc = VINF_SUCCESS;1421 1425 KLDRMODMACHO_ASSERT(!pThis->pvMapping); 1422 1426 … … 1432 1436 } 1433 1437 1434 if (pThis->Core.pReader)1435 {1436 rc = pThis->Core.pReader->pfnDestroy(pThis->Core.pReader);1437 pThis->Core.pReader = NULL;1438 }1439 pThis->Core.u32Magic = 0;1440 pThis->Core.pOps = NULL;1441 1438 RTMemFree(pThis->pbLoadCommands); 1442 1439 pThis->pbLoadCommands = NULL; … … 1445 1442 RTMemFree(pThis->pvaSymbols); 1446 1443 pThis->pvaSymbols = NULL; 1447 RTMemFree(pThis); 1448 return rc;1444 1445 return VINF_SUCCESS; 1449 1446 } 1450 1447 … … 2294 2291 2295 2292 #endif 2296 2297 static int kldrModMachOQueryImageUuid(PKLDRMODMACHO pThis, const void *pvBits, void *pvUuid, size_t cbUuid)2298 {2299 RT_NOREF(pvBits);2300 2301 memset(pvUuid, 0, cbUuid);2302 if (memcmp(pvUuid, pThis->abImageUuid, sizeof(pThis->abImageUuid)) == 0)2303 return VERR_NOT_FOUND;2304 2305 memcpy(pvUuid, pThis->abImageUuid, sizeof(pThis->abImageUuid));2306 return VINF_SUCCESS;2307 }2308 2293 2309 2294 … … 2748 2733 * @param pbSectBits Pointer to the section bits. 2749 2734 * @param pFixupSect The section being fixed up. 2735 * @param paSyms Pointer to the symbol table. 2736 * @param cSyms Number of symbols. 2750 2737 * @param NewBaseAddress The new base image address. 2751 2738 */ … … 2949 2936 * @param pbSectBits Pointer to the section bits. 2950 2937 * @param pFixupSect The section being fixed up. 2938 * @param paSyms Pointer to the symbol table. 2939 * @param cSyms Number of symbols. 2951 2940 * @param NewBaseAddress The new base image address. 2952 2941 */ … … 3776 3765 { 3777 3766 case RTLDRPROP_UUID: 3778 rc = kldrModMachOQueryImageUuid(pThis, pvBits, (uint8_t *)pvBuf, cbBuf); 3779 if (RT_FAILURE(rc)) 3780 return rc; 3781 cbBuf = RT_MIN(cbBuf, sizeof(RTUUID)); 3767 Assert(cbBuf >= sizeof(pThis->abImageUuid)); 3768 if (!ASMMemIsZero(pThis->abImageUuid, sizeof(pThis->abImageUuid))) 3769 { 3770 *pcbRet = sizeof(pThis->abImageUuid); 3771 memcpy(pvBuf, pThis->abImageUuid, sizeof(pThis->abImageUuid)); 3772 rc = VINF_SUCCESS; 3773 } 3774 else 3775 rc = VERR_NOT_FOUND; 3782 3776 break; 3783 3777 … … 3787 3781 3788 3782 default: 3789 return VERR_NOT_FOUND; 3790 } 3791 if (pcbRet) 3792 *pcbRet = cbBuf; 3783 rc = VERR_NOT_FOUND; 3784 break; 3785 } 3793 3786 RT_NOREF_PV(pvBits); 3794 return VINF_SUCCESS;3787 return rc; 3795 3788 } 3796 3789 -
trunk/src/VBox/Runtime/testcase/tstLdr-3.cpp
r69111 r74646 226 226 } 227 227 228 static uint32_t g_iSegNo = 0; 229 static DECLCALLBACK(int) testEnumSegment1(RTLDRMOD hLdrMod, PCRTLDRSEG pSeg, void *pvUser) 230 { 231 if (hLdrMod != g_hLdrMod || pvUser != NULL) 232 return VERR_INTERNAL_ERROR_3; 233 RTPrintf("Seg#%02u: %RTptr LB %RTptr %s\n", g_iSegNo++, pSeg->RVA, pSeg->cbMapped, pSeg->pszName); 234 235 return VINF_SUCCESS; 236 } 237 228 238 229 239 /** … … 239 249 static DECLCALLBACK(int) testEnumSymbol1(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTUINTPTR Value, void *pvUser) 240 250 { 241 RT_NOREF2(hLdrMod, pvUser); 251 if (hLdrMod != g_hLdrMod || pvUser != NULL) 252 return VERR_INTERNAL_ERROR_3; 242 253 RTPrintf(" %RTptr %s (%d)\n", Value, pszSymbol, uSymbol); 243 254 return VINF_SUCCESS; … … 354 365 rcRet++; 355 366 } 367 368 /* 369 * Query various properties. 370 */ 371 union 372 { 373 char szName[256]; 374 uint32_t iImpModule; 375 RTUUID Uuid; 376 } uBuf; 377 rc = RTLdrQueryProp(g_hLdrMod, RTLDRPROP_INTERNAL_NAME, &uBuf, sizeof(uBuf)); 378 if (RT_SUCCESS(rc)) 379 RTPrintf("tstLdr-3: Internal name: %s\n", uBuf.szName); 380 else if (rc != VERR_NOT_FOUND && rc != VERR_NOT_SUPPORTED) 381 { 382 RTPrintf("tstLdr-3: Internal name: failed - %Rrc\n", rc); 383 rcRet++; 384 } 385 386 uint32_t cImports = 0; 387 rc = RTLdrQueryProp(g_hLdrMod, RTLDRPROP_IMPORT_COUNT, &cImports, sizeof(cImports)); 388 if (RT_SUCCESS(rc)) 389 { 390 RTPrintf("tstLdr-3: Import count: %u\n", cImports); 391 for (uint32_t i = 0; i < cImports; i++) 392 { 393 uBuf.iImpModule = i; 394 rc = RTLdrQueryProp(g_hLdrMod, RTLDRPROP_IMPORT_MODULE, &uBuf, sizeof(uBuf)); 395 if (RT_SUCCESS(rc)) 396 RTPrintf("tstLdr-3: Import module #%u: %s\n", i, uBuf.szName); 397 else 398 { 399 RTPrintf("tstLdr-3: Import module #%u: failed - %Rrc\n", i, rc); 400 rcRet++; 401 } 402 } 403 } 404 else if (rc != VERR_NOT_FOUND && rc != VERR_NOT_SUPPORTED) 405 { 406 RTPrintf("tstLdr-3: Import count: failed - %Rrc\n", rc); 407 rcRet++; 408 } 409 410 rc = RTLdrQueryProp(g_hLdrMod, RTLDRPROP_UUID, &uBuf.Uuid, sizeof(uBuf.Uuid)); 411 if (RT_SUCCESS(rc)) 412 RTPrintf("tstLdr-3: UUID: %RTuuid\n", uBuf.Uuid); 413 else if (rc != VERR_NOT_FOUND && rc != VERR_NOT_SUPPORTED) 414 { 415 RTPrintf("tstLdr-3: UUID: failed - %Rrc\n", rc); 416 rcRet++; 417 } 418 419 /* 420 * Enumerate segments. 421 */ 422 RTPrintf("tstLdr-3: Segments:\n"); 423 rc = RTLdrEnumSegments(g_hLdrMod, testEnumSegment1, NULL); 424 if (RT_FAILURE(rc)) 425 { 426 RTPrintf("tstLdr-3: Failed to enumerate symbols: %Rra\n", rc); 427 rcRet++; 428 } 356 429 } 357 430 }
Note:
See TracChangeset
for help on using the changeset viewer.