VirtualBox

Ignore:
Timestamp:
Sep 12, 2008 2:42:49 PM (16 years ago)
Author:
vboxsync
Message:

IPRT/SUP: Renamed RTLdrOpenAppSharedLib to RTLdrOpenAppPriv. Hardend versions of RTLdrOpen and RTLdrOpenAppPriv. Use the hardend versions where appropriate.

File:
1 edited

Legend:

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

    r11888 r12423  
    137137
    138138/**
    139  * Loads a dynamic load library (/shared object) image file using native
    140  * OS facilities.
    141  *
    142  * If the path is specified in the filename, only this path is used.
    143  * If only the image file name is specified, then try to load it from:
    144  *   - RTPathAppPrivateArch
    145  *   - RTPathSharedLibs (legacy)
     139 * Loads a dynamic load library (/shared object) image file residing in the
     140 * RTPathAppPrivateArch() directory.
     141 *
     142 * Suffix is not required.
    146143 *
    147144 * @returns iprt status code.
    148  * @param   pszFilename Image filename.
     145 * @param   pszFilename Image filename. No path.
    149146 * @param   phLdrMod    Where to store the handle to the loaded module.
    150147 */
    151 RTDECL(int) RTLdrLoadAppSharedLib(const char *pszFilename, PRTLDRMOD phLdrMod)
    152 {
    153     LogFlow(("RTLdrLoadAppSharedLib: pszFilename=%p:{%s} phLdrMod=%p\n", pszFilename, pszFilename, phLdrMod));
     148RTDECL(int) RTLdrLoadAppPriv(const char *pszFilename, PRTLDRMOD phLdrMod)
     149{
     150    LogFlow(("RTLdrLoadAppPriv: pszFilename=%p:{%s} phLdrMod=%p\n", pszFilename, pszFilename, phLdrMod));
    154151
    155152    /*
    156153     * Validate input.
    157154     */
    158     AssertMsgReturn(VALID_PTR(pszFilename), ("pszFilename=%p\n", pszFilename), VERR_INVALID_PARAMETER);
    159     AssertMsgReturn(VALID_PTR(phLdrMod), ("phLdrMod=%p\n", phLdrMod), VERR_INVALID_PARAMETER);
    160 
    161     /*
    162      * If a path is specified, just load the file.
    163      */
    164     if (RTPathHavePath(pszFilename))
    165         return RTLdrLoad(pszFilename, phLdrMod);
    166 
    167     /*
    168      * By default nothing is found.
    169      */
    170     int rc = VERR_FILE_NOT_FOUND;
     155    AssertPtrReturn(phLdrMod, VERR_INVALID_PARAMETER);
    171156    *phLdrMod = NIL_RTLDRMOD;
    172 
    173     /*
    174      * Try default locations.
    175      */
    176     int i;
    177     for (i = 0;; i++)
     157    AssertPtrReturn(pszFilename, VERR_INVALID_PARAMETER);
     158    AssertMsgReturn(!RTPathHavePath(pszFilename), ("%s\n", pszFilename), VERR_INVALID_PARAMETER);
     159
     160    /*
     161     * Check the filename.
     162     */
     163    size_t cchFilename = strlen(pszFilename);
     164    AssertMsgReturn(cchFilename > (RTPATH_MAX / 4) * 3, ("%zu\n", cchFilename), VERR_INVALID_PARAMETER);
     165
     166    const char *pszExt = "";
     167    size_t cchExt = 0;
     168    if (!RTPathHaveExt(pszFilename))
    178169    {
    179         /*
    180          * Get the appropriate base path.
    181          */
    182         char szBase[RTPATH_MAX];
    183         if (i == 0)
    184             rc = RTPathAppPrivateArch(szBase, sizeof (szBase));
    185         else if (i == 1)
    186             rc = RTPathSharedLibs(szBase, sizeof (szBase));
    187         else
    188             break;
    189 
    190         if (RT_SUCCESS(rc))
    191         {
    192             /*
    193              * Got the base path. Construct szPath = pszBase + pszFilename
    194              */
    195             char szPath[RTPATH_MAX];
    196             rc = RTPathAbsEx(szBase, pszFilename, szPath, sizeof (szPath));
    197             if (RT_SUCCESS(rc))
    198             {
    199                 /*
    200                  * Finally try to load the image file.
    201                  */
    202                 rc = RTLdrLoad(szPath, phLdrMod);
    203                 if (RT_SUCCESS(rc))
    204                 {
    205                     /*
    206                      * Successfully loaded the image file.
    207                      */
    208                     LogFlow(("Library loaded: [%s]\n", szPath));
    209                     break;
    210                 }
    211             }
    212         }
     170        pszExt = RTLdrGetSuff();
     171        cchExt = strlen(pszExt);
    213172    }
    214     LogFlow(("RTLdrLoadAppSharedLib: returns %Rrc\n", rc));
     173
     174    /*
     175     * Construct the private arch path and check if the file exists.
     176     */
     177    char szPath[RTPATH_MAX];
     178    int rc = RTPathAppPrivateArch(szPath, sizeof(szPath) - 1 - cchExt - cchFilename);
     179    AssertRCReturn(rc, rc);
     180
     181    char *psz = strchr(szPath, '\0');
     182    *psz++ = RTPATH_SLASH;
     183    memcpy(psz, pszFilename, cchFilename);
     184    psz += cchFilename;
     185    memcpy(psz, pszExt, cchExt + 1);
     186
     187    if (!RTPathExists(szPath))
     188    {
     189        LogRel(("RTLdrLoadAppPriv: \"%s\" not found\n", szPath));
     190        return VERR_FILE_NOT_FOUND;
     191    }
     192
     193    /*
     194     * Pass it on to RTLdrLoad.
     195     */
     196    rc = RTLdrLoad(szPath, phLdrMod);
     197
     198    LogFlow(("RTLdrLoadAppPriv: returns %Rrc\n", rc));
    215199    return rc;
    216200}
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