VirtualBox

Changeset 85540 in vbox for trunk


Ignore:
Timestamp:
Jul 30, 2020 9:05:37 AM (4 years ago)
Author:
vboxsync
Message:

IPRT/ldrELF: Fixed issue in GetNextAllocatedSection causing cbMapped to always be zero. bugref:9801

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/ldr/ldrELFRelocatable.cpp.h

    r85525 r85540  
    13621362
    13631363/**
    1364  * Helper that locates the first allocated section.
     1364 * Locate the next allocated section by RVA (sh_addr).
     1365 *
     1366 * This is a helper for EnumSegments and SegOffsetToRva.
    13651367 *
    13661368 * @returns Pointer to the section header if found, NULL if none.
    1367  * @param   pShdr   The section header to start searching at.
    1368  * @param   cLeft   The number of section headers left to search. Can be 0.
     1369 * @param   pModElf     The module instance.
     1370 * @param   iShdrCur    The current section header.
    13691371 */
    1370 static const Elf_Shdr *RTLDRELF_NAME(GetFirstAllocatedSection)(const Elf_Shdr *pShdr, unsigned cLeft)
    1371 {
    1372     while (cLeft-- > 0)
    1373     {
    1374         if (pShdr->sh_flags & SHF_ALLOC)
    1375             return pShdr;
    1376         pShdr++;
    1377     }
    1378     return NULL;
    1379 }
    1380 
    1381 /**
    1382  * Helper that locates the next allocated section logically by RVA (sh_addr).
    1383  *
    1384  * @returns Pointer to the section header if found, NULL if none.
    1385  * @param   pModElf The module instance.
    1386  * @param   iCur    The current section header.
    1387  */
    1388 static const Elf_Shdr *RTLDRELF_NAME(GetNextAllocatedSection)(PRTLDRMODELF pModElf, unsigned iCur)
     1372static const Elf_Shdr *RTLDRELF_NAME(GetNextAllocatedSection)(PRTLDRMODELF pModElf, unsigned iShdrCur)
    13891373{
    13901374    unsigned const          cShdrs  = pModElf->Ehdr.e_shnum;
     
    13921376    if (pModElf->fShdrInOrder)
    13931377    {
    1394         for (; iCur < cShdrs; iCur++)
    1395             if (paShdrs[iCur].sh_flags & SHF_ALLOC)
    1396                 return &paShdrs[iCur];
     1378        for (unsigned iShdr = iShdrCur + 1; iShdr < cShdrs; iShdr++)
     1379            if (paShdrs[iShdr].sh_flags & SHF_ALLOC)
     1380                return &paShdrs[iShdr];
    13971381    }
    13981382    else
    13991383    {
    1400         Elf_Addr const uEndCur = paShdrs[iCur].sh_addr + paShdrs[iCur].sh_size;
     1384        Elf_Addr const uEndCur = paShdrs[iShdrCur].sh_addr + paShdrs[iShdrCur].sh_size;
    14011385        Elf_Addr       offBest = ~(Elf_Addr)0;
    14021386        unsigned       iBest   = cShdrs;
    1403         for (iCur = pModElf->iFirstSect; iCur < cShdrs; iCur++)
    1404             if (paShdrs[iCur].sh_flags & SHF_ALLOC)
    1405             {
    1406                 Elf_Addr const offDelta = paShdrs[iCur].sh_addr - uEndCur;
     1387        for (unsigned iShdr = pModElf->iFirstSect; iShdr < cShdrs; iShdr++)
     1388            if ((paShdrs[iShdr].sh_flags & SHF_ALLOC) && iShdr != iShdrCur)
     1389            {
     1390                Elf_Addr const offDelta = paShdrs[iShdr].sh_addr - uEndCur;
    14071391                if (   offDelta < offBest
    1408                     && paShdrs[iCur].sh_addr >= uEndCur)
     1392                    && paShdrs[iShdr].sh_addr >= uEndCur)
    14091393                {
    14101394                    offBest = offDelta;
    1411                     iBest = iCur;
     1395                    iBest   = iShdr;
    14121396                }
    14131397            }
     
    14171401    return NULL;
    14181402}
     1403
    14191404
    14201405/** @copydoc RTLDROPS::pfnEnumSegments. */
     
    15631548    if (offSeg > pModElf->paShdrs[iSeg].sh_size)
    15641549    {
    1565         const Elf_Shdr *pShdr2 = RTLDRELF_NAME(GetFirstAllocatedSection)(&pModElf->paShdrs[iSeg + 1],
    1566                                                                          pModElf->Ehdr.e_shnum - iSeg - 1);
     1550        const Elf_Shdr *pShdr2 = RTLDRELF_NAME(GetNextAllocatedSection)(pModElf, iSeg);
    15671551        if (   !pShdr2
    15681552            || offSeg > (pShdr2->sh_addr - pModElf->paShdrs[iSeg].sh_addr))
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette