Avoid hard-coded command line length limit in WCMD_process_command.

This commit is contained in:
Alexandre Julliard 2003-07-09 22:21:04 +00:00
parent ea6863c182
commit 9fc5e6f098
1 changed files with 17 additions and 12 deletions

View File

@ -253,11 +253,10 @@ int main (int argc, char *argv[])
*/ */
void WCMD_process_command (char *command) { void WCMD_process_command (char *command)
{
char cmd[1024]; char *cmd, *p;
char *p; int status, i, len;
int status, i;
DWORD count; DWORD count;
HANDLE old_stdin = 0, old_stdout = 0, h; HANDLE old_stdin = 0, old_stdout = 0, h;
char *whichcmd; char *whichcmd;
@ -266,10 +265,12 @@ char *whichcmd;
/* /*
* Expand up environment variables. * Expand up environment variables.
*/ */
len = ExpandEnvironmentStrings (command, NULL, 0);
status = ExpandEnvironmentStrings (command, cmd, sizeof(cmd)); cmd = HeapAlloc( GetProcessHeap(), 0, len );
status = ExpandEnvironmentStrings (command, cmd, len);
if (!status) { if (!status) {
WCMD_print_error (); WCMD_print_error ();
HeapFree( GetProcessHeap(), 0, cmd );
return; return;
} }
@ -280,6 +281,7 @@ char *whichcmd;
if ((cmd[1] == ':') && IsCharAlpha (cmd[0]) && (strlen(cmd) == 2)) { if ((cmd[1] == ':') && IsCharAlpha (cmd[0]) && (strlen(cmd) == 2)) {
status = SetCurrentDirectory (cmd); status = SetCurrentDirectory (cmd);
if (!status) WCMD_print_error (); if (!status) WCMD_print_error ();
HeapFree( GetProcessHeap(), 0, cmd );
return; return;
} }
@ -294,6 +296,7 @@ char *whichcmd;
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
WCMD_print_error (); WCMD_print_error ();
HeapFree( GetProcessHeap(), 0, cmd );
return; return;
} }
old_stdin = GetStdHandle (STD_INPUT_HANDLE); old_stdin = GetStdHandle (STD_INPUT_HANDLE);
@ -304,6 +307,7 @@ char *whichcmd;
FILE_ATTRIBUTE_NORMAL, NULL); FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) { if (h == INVALID_HANDLE_VALUE) {
WCMD_print_error (); WCMD_print_error ();
HeapFree( GetProcessHeap(), 0, cmd );
return; return;
} }
old_stdout = GetStdHandle (STD_OUTPUT_HANDLE); old_stdout = GetStdHandle (STD_OUTPUT_HANDLE);
@ -442,7 +446,8 @@ char *whichcmd;
ExitProcess (0); ExitProcess (0);
default: default:
WCMD_run_program (whichcmd); WCMD_run_program (whichcmd);
}; }
HeapFree( GetProcessHeap(), 0, cmd );
if (old_stdin) { if (old_stdin) {
CloseHandle (GetStdHandle (STD_INPUT_HANDLE)); CloseHandle (GetStdHandle (STD_INPUT_HANDLE));
SetStdHandle (STD_INPUT_HANDLE, old_stdin); SetStdHandle (STD_INPUT_HANDLE, old_stdin);