VirtualBox

Changeset 43062 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 29, 2012 9:46:14 AM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
80403
Message:

Main/GuestProcessImpl: Fixed leak when building up argv vector.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp

    r43061 r43062  
    10831083        char *pszArgs = NULL;
    10841084        size_t cArgs = mData.mProcess.mArguments.size();
    1085         if (cArgs)
    1086         {
    1087             char **papszArgv = (char**)RTMemAlloc(sizeof(char*) * (cArgs + 1));
     1085        if (cArgs >= UINT32_MAX)
     1086            vrc = VERR_BUFFER_OVERFLOW;
     1087
     1088        if (   RT_SUCCESS(vrc)
     1089            && cArgs)
     1090        {
     1091            char **papszArgv = (char**)RTMemAlloc((cArgs + 1) * sizeof(char*));
    10881092            AssertReturn(papszArgv, VERR_NO_MEMORY);
    1089             for (size_t i = 0; RT_SUCCESS(vrc) && i < cArgs; i++)
    1090                 vrc = RTStrDupEx(&papszArgv[i], mData.mProcess.mArguments[i].c_str());
     1093
     1094            for (size_t i = 0; i < cArgs && RT_SUCCESS(vrc); i++)
     1095            {
     1096                const char *pszCurArg = mData.mProcess.mArguments[i].c_str();
     1097                AssertPtr(pszCurArg);
     1098                vrc = RTStrDupEx(&papszArgv[i], pszCurArg);
     1099            }
    10911100            papszArgv[cArgs] = NULL;
    10921101
    10931102            if (RT_SUCCESS(vrc))
    10941103                vrc = RTGetOptArgvToString(&pszArgs, papszArgv, RTGETOPTARGV_CNV_QUOTE_MS_CRT);
    1095         }
    1096         size_t cbArgs = pszArgs ? strlen(pszArgs) + 1 : 0; /* Include terminating zero. */
     1104
     1105            if (papszArgv)
     1106            {
     1107                size_t i = 0;
     1108                while (papszArgv[i])
     1109                    RTStrFree(papszArgv[i++]);
     1110                RTMemFree(papszArgv);
     1111            }
     1112        }
     1113
     1114        /* Calculate arguments size (in bytes). */
     1115        size_t cbArgs = 0;
     1116        if (RT_SUCCESS(vrc))
     1117            cbArgs = pszArgs ? strlen(pszArgs) + 1 : 0; /* Include terminating zero. */
    10971118
    10981119        /* Prepare environment. */
    10991120        void *pvEnv = NULL;
    11001121        size_t cbEnv = 0;
    1101         vrc = mData.mProcess.mEnvironment.BuildEnvironmentBlock(&pvEnv, &cbEnv, NULL /* cEnv */);
     1122        if (RT_SUCCESS(vrc))
     1123            vrc = mData.mProcess.mEnvironment.BuildEnvironmentBlock(&pvEnv, &cbEnv, NULL /* cEnv */);
    11021124
    11031125        if (RT_SUCCESS(vrc))
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