VirtualBox

Ignore:
Timestamp:
May 24, 2012 9:38:38 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
78155
Message:

tstInt: use absolute path because of hardening

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/Support/testcase/tstInt.cpp

    r38636 r41429  
    4040#include <iprt/alloc.h>
    4141#include <iprt/time.h>
    42 
    43 
    44 /**
    45  * Makes a path to a file in the executable directory.
    46  */
    47 static char *ExeDirFile(char *pszFile, const char *pszArgv0, const char *pszFilename)
    48 {
    49     char   *psz;
    50     char   *psz2;
    51 
    52     strcpy(pszFile, pszArgv0);
    53     psz = strrchr(pszFile, '/');
    54     psz2 = strrchr(pszFile, '\\');
    55     if (psz < psz2)
    56         psz = psz2;
    57     if (!psz)
    58         psz = strrchr(pszFile, ':');
    59     if (!psz)
    60     {
    61         strcpy(pszFile, "./");
    62         psz = &pszFile[1];
    63     }
    64     strcpy(psz + 1, "VMMR0.r0");
    65     return pszFile;
    66 }
     42#include <iprt/path.h>
     43
    6744
    6845int main(int argc, char **argv)
     
    8360    rcRet += rc != 0;
    8461    RTPrintf("tstInt: SUPR3Init -> rc=%Rrc\n", rc);
     62    char szFile[RTPATH_MAX];
    8563    if (!rc)
     64    {
     65        rc = RTPathExecDir(szFile, sizeof(szFile) - sizeof("/VMMR0.r0"));
     66    }
     67    char szAbsFile[RTPATH_MAX];
     68    if (RT_SUCCESS(rc))
     69    {
     70        strcat(szFile, "/VMMR0.r0");
     71        rc = RTPathAbs(szFile, szAbsFile, sizeof(szAbsFile));
     72    }
     73    if (RT_SUCCESS(rc))
    8674    {
    8775        /*
    8876         * Load VMM code.
    8977         */
    90         char    szFile[RTPATH_MAX];
    91         rc = SUPR3LoadVMM(ExeDirFile(szFile, argv[0], "VMMR0.r0"));
    92         if (!rc)
     78        rc = SUPR3LoadVMM(szAbsFile);
     79        if (RT_SUCCESS(rc))
    9380        {
    9481            /*
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