third_party/virtualbox/src/VBox/HostDrivers/Support/SUPR3HardenedMain.cpp
/**
 * Purges any command line arguments considered harmful.
 *
 * @returns nothing.
 * @param   cArgsOrig        The original number of arguments.
 * @param   papszArgsOrig    The original argument vector.
 * @param   pcArgsNew        Where to store the new number of arguments on success.
 * @param   ppapszArgsNew    Where to store the pointer to the purged argument vector.
 */
Purges any command line arguments considered harmful.
@returns nothing.
@param   cArgsOrig        The original number of arguments.
@param   papszArgsOrig    The original argument vector.
@param   pcArgsNew        Where to store the new number of arguments on success.
@param   ppapszArgsNew    Where to store the pointer to the purged argument vector.
Purges any command line arguments considered harmful . @returns nothing . @param cArgsOrig The original number of arguments . @param papszArgsOrig The original argument vector . @param pcArgsNew Where to store the new number of arguments on success . @param ppapszArgsNew Where to store the pointer to the purged argument vector .
static void supR3HardenedMainPurgeArgs(int cArgsOrig, char **papszArgsOrig, int *pcArgsNew, char ***ppapszArgsNew)
{
    int    iDst = 0;
#ifdef RT_OS_WINDOWS
    char **papszArgsNew = papszArgsOrig; 
#else
    char **papszArgsNew = (char **)malloc((cArgsOrig + 1) * sizeof(char *));
#endif
    if (papszArgsNew)
    {
        for (int iSrc = 0; iSrc < cArgsOrig; iSrc++)
        {
            unsigned cPurgedArgs = supR3HardenedMainShouldPurgeArg(papszArgsOrig[iSrc]);
            if (!cPurgedArgs)
                papszArgsNew[iDst++] = papszArgsOrig[iSrc];
            else
                iSrc += cPurgedArgs - 1;
        }
        papszArgsNew[iDst] = NULL; 
    }
    else
        supR3HardenedFatal("SUPR3HardenedMain: failed to allocate memory for purged command line!\n");
    *pcArgsNew     = iDst;
    *ppapszArgsNew = papszArgsNew;
#ifdef RT_OS_WINDOWS
#endif
}
static void supR3HardenedMainPurgeArgs ( int cArgsOrig , char * * papszArgsOrig , int * pcArgsNew , char * * * ppapszArgsNew ) { int iDst = 0 ; #ifdef RT_OS_WINDOWS char * * papszArgsNew = papszArgsOrig ; #else char * * papszArgsNew = ( char * * ) malloc ( ( cArgsOrig + 1 ) * sizeof ( char * ) ) ; #endif if ( papszArgsNew ) { for ( int iSrc = 0 ; iSrc < cArgsOrig ; iSrc ++ ) { unsigned cPurgedArgs = supR3HardenedMainShouldPurgeArg ( papszArgsOrig [ iSrc ] ) ; if ( ! cPurgedArgs ) papszArgsNew [ iDst ++ ] = papszArgsOrig [ iSrc ] ; else iSrc += cPurgedArgs - 1 ; } papszArgsNew [ iDst ] = NULL ; } else supR3HardenedFatal ( " \n " ) ; * pcArgsNew = iDst ; * ppapszArgsNew = papszArgsNew ; #ifdef RT_OS_WINDOWS #endif }
Purges any command line arguments considered harmful.
Purges any command line arguments considered harmful .
/* We allocated this, no need to allocate again. */ /* The array is NULL terminated, just like envp. */ /** @todo Update command line pointers in PEB, wont really work without it. */