VirtualBox

Changeset 69253 in vbox for trunk/src/bldprogs


Ignore:
Timestamp:
Oct 24, 2017 7:32:58 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
118568
Message:

scm: Fixed bad abspath assumption in scmSettingsLoadFile.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bldprogs/scm.cpp

    r69244 r69253  
    943943 * @returns IPRT status code.
    944944 * @param   pSettings           Where to load the settings file.
    945  * @param   pszFilename         The file to load.  ASSUMED to be absolute.
    946  * @param   offName             The offset of the name part in pszFilename.
    947  */
    948 static int scmSettingsLoadFile(PSCMSETTINGS pSettings, const char *pszFilename, size_t offName)
     945 * @param   pszFilename         The file to load.
     946 */
     947static int scmSettingsLoadFile(PSCMSETTINGS pSettings, const char *pszFilename)
    949948{
    950949    ScmVerbose(NULL, 3, "Loading settings file '%s'...\n", pszFilename);
    951950
    952 #ifdef RT_STRICT
    953     /* Check absolute path assumption. */
    954     char szTmp[RTPATH_MAX];
    955     int rcTmp = RTPathAbs(pszFilename, szTmp, sizeof(szTmp));
    956     AssertMsg(RT_SUCCESS(rcTmp) && RTPathCompare(szTmp, pszFilename) == 0, ("rcTmp=%Rrc pszFilename='%s'\n", rcTmp, pszFilename));
    957 #endif
    958 
     951    /* Turn filename into an absolute path and drop the filename. */
     952    char szAbsPath[RTPATH_MAX];
     953    int rc = RTPathAbs(pszFilename, szAbsPath, sizeof(szAbsPath));
     954    if (RT_FAILURE(rc))
     955    {
     956        RTMsgError("%s: RTPathAbs -> %Rrc\n", pszFilename, rc);
     957        return rc;
     958    }
     959    RTPathChangeToUnixSlashes(szAbsPath, true);
     960    size_t cchDir = RTPathFilename(szAbsPath) - &szAbsPath[0];
     961
     962    /* Try open it.*/
    959963    SCMSTREAM Stream;
    960     int rc = ScmStreamInitForReading(&Stream, pszFilename);
    961     if (RT_FAILURE(rc))
    962     {
     964    rc = ScmStreamInitForReading(&Stream, pszFilename);
     965    if (RT_SUCCESS(rc))
     966    {
     967        SCMEOL      enmEol;
     968        const char *pchLine;
     969        size_t      cchLine;
     970        while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL)
     971        {
     972            /* Ignore leading spaces. */
     973            while (cchLine > 0 && RT_C_IS_SPACE(*pchLine))
     974                pchLine++, cchLine--;
     975
     976            /* Ignore empty lines and comment lines. */
     977            if (cchLine < 1 || *pchLine == '#')
     978                continue;
     979
     980            /* What kind of line is it? */
     981            const char *pchColon = (const char *)memchr(pchLine, ':', cchLine);
     982            if (pchColon)
     983                rc = scmSettingsAddPair(pSettings, pchLine, cchLine, pchColon - pchLine, szAbsPath, cchDir);
     984            else
     985                rc = scmSettingsBaseParseStringN(&pSettings->Base, pchLine, cchLine, szAbsPath, cchDir);
     986            if (RT_FAILURE(rc))
     987            {
     988                RTMsgError("%s:%d: %Rrc\n", pszFilename, ScmStreamTellLine(&Stream), rc);
     989                break;
     990            }
     991        }
     992
     993        if (RT_SUCCESS(rc))
     994        {
     995            rc = ScmStreamGetStatus(&Stream);
     996            if (RT_FAILURE(rc))
     997                RTMsgError("%s: ScmStreamGetStatus- > %Rrc\n", pszFilename, rc);
     998        }
     999        ScmStreamDelete(&Stream);
     1000    }
     1001    else
    9631002        RTMsgError("%s: ScmStreamInitForReading -> %Rrc\n", pszFilename, rc);
    964         return rc;
    965     }
    966 
    967     SCMEOL      enmEol;
    968     const char *pchLine;
    969     size_t      cchLine;
    970     while ((pchLine = ScmStreamGetLine(&Stream, &cchLine, &enmEol)) != NULL)
    971     {
    972         /* Ignore leading spaces. */
    973         while (cchLine > 0 && RT_C_IS_SPACE(*pchLine))
    974             pchLine++, cchLine--;
    975 
    976         /* Ignore empty lines and comment lines. */
    977         if (cchLine < 1 || *pchLine == '#')
    978             continue;
    979 
    980         /* What kind of line is it? */
    981         const char *pchColon = (const char *)memchr(pchLine, ':', cchLine);
    982         if (pchColon)
    983             rc = scmSettingsAddPair(pSettings, pchLine, cchLine, pchColon - pchLine, pszFilename, offName);
    984         else
    985             rc = scmSettingsBaseParseStringN(&pSettings->Base, pchLine, cchLine, pszFilename, offName);
    986         if (RT_FAILURE(rc))
    987         {
    988             RTMsgError("%s:%d: %Rrc\n", pszFilename, ScmStreamTellLine(&Stream), rc);
    989             break;
    990         }
    991     }
    992 
    993     if (RT_SUCCESS(rc))
    994     {
    995         rc = ScmStreamGetStatus(&Stream);
    996         if (RT_FAILURE(rc))
    997             RTMsgError("%s: ScmStreamGetStatus- > %Rrc\n", pszFilename, rc);
    998     }
    999 
    1000     ScmStreamDelete(&Stream);
    10011003    return rc;
    10021004}
     
    10821084        if (RTFileExists(szFile))
    10831085        {
    1084             rc = scmSettingsLoadFile(pSettings, szFile, RTPathFilename(szFile) - &szFile[0]);
     1086            rc = scmSettingsLoadFile(pSettings, szFile);
    10851087            if (RT_FAILURE(rc))
    10861088                break;
     
    11361138        {
    11371139            if (RTFileExists(szFile))
    1138                 rc = scmSettingsLoadFile(pSettings, szFile, RTPathFilename(szFile) - &szFile[0]);
     1140                rc = scmSettingsLoadFile(pSettings, szFile);
    11391141            if (RT_SUCCESS(rc))
    11401142            {
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