cmd: Ensure environment variables fit in memory.

This commit is contained in:
Bruno Jesus 2015-01-06 14:55:01 -02:00 committed by Alexandre Julliard
parent de09e9b94e
commit 5a469f1b87
1 changed files with 12 additions and 4 deletions

View File

@ -496,15 +496,23 @@ void WCMD_HandleTildaModifiers(WCHAR **start, BOOL atExecute)
WCHAR *begin = strchrW(firstModifier, '$') + 1; WCHAR *begin = strchrW(firstModifier, '$') + 1;
WCHAR *end = strchrW(firstModifier, ':'); WCHAR *end = strchrW(firstModifier, ':');
WCHAR env[MAX_PATH]; WCHAR env[MAX_PATH];
WCHAR fullpath[MAX_PATH]; DWORD size;
/* Extract the env var */ /* Extract the env var */
memcpy(env, begin, (end-begin) * sizeof(WCHAR)); memcpy(env, begin, (end-begin) * sizeof(WCHAR));
env[(end-begin)] = 0x00; env[(end-begin)] = 0x00;
/* If env var not found, return empty string */ size = GetEnvironmentVariableW(env, NULL, 0);
if ((GetEnvironmentVariableW(env, fullpath, MAX_PATH) == 0) || if (size > 0) {
(SearchPathW(fullpath, outputparam, NULL, MAX_PATH, outputparam, NULL) == 0)) { WCHAR *fullpath = heap_alloc(size * sizeof(WCHAR));
if (!fullpath || (GetEnvironmentVariableW(env, fullpath, size) == 0) ||
(SearchPathW(fullpath, outputparam, NULL, MAX_PATH, outputparam, NULL) == 0))
size = 0;
heap_free(fullpath);
}
if (!size) {
/* If env var not found, return empty string */
finaloutput[0] = 0x00; finaloutput[0] = 0x00;
outputparam[0] = 0x00; outputparam[0] = 0x00;
skipFileParsing = TRUE; skipFileParsing = TRUE;