VirtualBox

Changeset 45982 in vbox for trunk


Ignore:
Timestamp:
May 10, 2013 12:36:39 PM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
85636
Message:

RTLdrElf: Better fix.

Location:
trunk/src/VBox/Runtime/common/ldr
Files:
2 edited

Legend:

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

    r44528 r45982  
    4949*   Defined Constants And Macros                                               *
    5050*******************************************************************************/
    51 /** Finds an ELF string. */
     51/** Finds an ELF symbol table string. */
    5252#define ELF_STR(pHdrs, iStr) ((pHdrs)->pStr + (iStr))
     53/** Finds an ELF section header string. */
     54#define ELF_SH_STR(pHdrs, iStr) ((pHdrs)->pShStr + (iStr))
    5355
    5456
  • trunk/src/VBox/Runtime/common/ldr/ldrELFRelocatable.cpp.h

    r45981 r45982  
    124124    /** Pointer to string table within RTLDRMODELF::pvBits. */
    125125    const char             *pStr;
     126
     127    /** Size of the section header string table. */
     128    unsigned                cbShStr;
     129    /** Pointer to section header string table within RTLDRMODELF::pvBits. */
     130    const char             *pShStr;
    126131} RTLDRMODELF, *PRTLDRMODELF;
    127132
     
    148153        if (pModElf->iStrSh != ~0U)
    149154            pModElf->pStr   =    (const char *)(pu8 + pModElf->paShdrs[pModElf->iStrSh].sh_offset);
     155        pModElf->pShStr     =    (const char *)(pu8 + pModElf->paShdrs[pModElf->Ehdr.e_shstrndx].sh_offset);
    150156    }
    151157    return rc;
     
    644650         */
    645651        Log2(("rtldrELF: %s: Relocation records for #%d [%s] (sh_info=%d sh_link=%d) found in #%d [%s] (sh_info=%d sh_link=%d)\n",
    646               pszLogName, (int)pShdrRel->sh_info, ELF_STR(pModElf, pShdr->sh_name), (int)pShdr->sh_info, (int)pShdr->sh_link,
    647               iShdr, ELF_STR(pModElf, pShdrRel->sh_name), (int)pShdrRel->sh_info, (int)pShdrRel->sh_link));
     652              pszLogName, (int)pShdrRel->sh_info, ELF_SH_STR(pModElf, pShdr->sh_name), (int)pShdr->sh_info, (int)pShdr->sh_link,
     653              iShdr, ELF_SH_STR(pModElf, pShdrRel->sh_name), (int)pShdrRel->sh_info, (int)pShdrRel->sh_link));
    648654
    649655        /** @todo Make RelocateSection a function pointer so we can select the one corresponding to the machine when opening the image. */
     
    754760            continue;
    755761
    756         const char *pszSectName = ELF_STR(pModElf, paShdrs[iShdr].sh_name);
     762        const char *pszSectName = ELF_SH_STR(pModElf, paShdrs[iShdr].sh_name);
    757763        if (   !strncmp(pszSectName, RT_STR_TUPLE(".debug_"))
    758764            || !strcmp(pszSectName, ".WATCOM_references") )
     
    830836    {
    831837        RTLDRSEG Seg;
    832         Seg.pchName     = ELF_STR(pModElf, paShdrs[iShdr].sh_name);
     838        Seg.pchName     = ELF_SH_STR(pModElf, paShdrs[iShdr].sh_name);
    833839        Seg.cchName     = (uint32_t)strlen(Seg.pchName);
    834840        Seg.SelFlat     = 0;
     
    11471153    }
    11481154
     1155    if (pEhdr->e_shstrndx == 0 || pEhdr->e_shstrndx > pEhdr->e_shnum)
     1156    {
     1157        Log(("RTLdrELF: %s: The section headers string table is out of bounds! e_shstrndx=" FMT_ELF_HALF " e_shnum=" FMT_ELF_HALF "\n",
     1158             pszLogName, pEhdr->e_shstrndx, pEhdr->e_shnum));
     1159        return VERR_BAD_EXE_FORMAT;
     1160    }
     1161
    11491162    return VINF_SUCCESS;
    11501163}
     
    12321245    }
    12331246
     1247    if (pShdr->sh_name >= pModElf->cbShStr)
     1248    {
     1249        Log(("RTLdrELF: %s: Shdr #%d: sh_name (%d) is beyond the end of the section header string table (%d)!\n",
     1250             pszLogName, iShdr, pShdr->sh_name, pModElf->cbShStr)); NOREF(pszLogName);
     1251        return VERR_BAD_EXE_FORMAT;
     1252    }
     1253
    12341254    if (pShdr->sh_link >= pModElf->Ehdr.e_shnum)
    12351255    {
     
    13301350    //pModElf->paSyms         = NULL;
    13311351    pModElf->iSymSh         = ~0U;
    1332     pModElf->cSyms          = 0;
     1352    //pModElf->cSyms          = 0;
    13331353    pModElf->iStrSh         = ~0U;
    1334     pModElf->cbStr          = 0;
    1335     pModElf->cbImage        = 0;
     1354    //pModElf->cbStr          = 0;
     1355    //pModElf->cbImage        = 0;
    13361356    //pModElf->pStr           = NULL;
     1357    //pModElf->cbShStr        = 0;
     1358    //pModElf->pShStr         = NULL;
    13371359
    13381360    /*
     
    13671389                memcpy(&paShdrs[pModElf->Ehdr.e_shnum], paShdrs, cbShdrs);
    13681390                pModElf->paOrgShdrs = &paShdrs[pModElf->Ehdr.e_shnum];
     1391
     1392                pModElf->cbShStr = paShdrs[pModElf->Ehdr.e_shstrndx].sh_size;
    13691393
    13701394                /*
     
    14071431                        AssertReturn(pModElf->cbStr == paShdrs[pModElf->iStrSh].sh_size, VERR_IMAGE_TOO_BIG);
    14081432                    }
    1409                     else if (paShdrs[i].sh_type == SHT_STRTAB && pModElf->iStrSh == ~0U)
     1433
     1434                    /* Special checks for the section string table. */
     1435                    if (i == pModElf->Ehdr.e_shstrndx)
    14101436                    {
    1411                         pModElf->iStrSh = i;
    1412                         pModElf->cbStr  = (unsigned)paShdrs[i].sh_size;
    1413                         AssertReturn(pModElf->cbStr == paShdrs[i].sh_size, VERR_IMAGE_TOO_BIG);
     1437                        if (paShdrs[i].sh_type != SHT_STRTAB)
     1438                        {
     1439                            Log(("RTLdrElf: Section header string table is not a SHT_STRTAB: %#x\n", paShdrs[i].sh_type));
     1440                            rc = VERR_BAD_EXE_FORMAT;
     1441                            break;
     1442                        }
     1443                        if (paShdrs[i].sh_size == 0)
     1444                        {
     1445                            Log(("RTLdrElf: Section header string table is empty\n"));
     1446                            rc = VERR_BAD_EXE_FORMAT;
     1447                            break;
     1448                        }
    14141449                    }
    14151450
     
    14181453                Log2(("RTLdrElf: iSymSh=%u cSyms=%u iStrSh=%u cbStr=%u rc=%Rrc cbImage=%#zx\n",
    14191454                      pModElf->iSymSh, pModElf->cSyms, pModElf->iStrSh, pModElf->cbStr, rc, pModElf->cbImage));
    1420 #if 0
    1421                 /*
    1422                  * Are the section headers fine?
    1423                  * We require there to be symbol & string tables (at least for the time being).
    1424                  */
    1425                 if (    pModElf->iSymSh == ~0U
    1426                     ||  pModElf->iStrSh == ~0U)
    1427                     rc = VERR_LDRELF_NO_SYMBOL_OR_NO_STRING_TABS;
    1428 #endif
    14291455                if (RT_SUCCESS(rc))
    14301456                {
Note: See TracChangeset for help on using the changeset viewer.

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