- Implement X>&Y redirections. Hold redirections in a linked list structure, because order matters (>x 2>&1 is not the same as 2>&1 >x). Allow redirection of any handle number from 0 to 9.

- Allow quotes around the redirection file name.
- Batch: Fix buffer overflow bug (incorrect size for bc->BatchFilePath)

svn path=/trunk/; revision=35508
This commit is contained in:
Jeffrey Morlan 2008-08-21 15:33:59 +00:00
parent 4af7567008
commit 07912f2b23
9 changed files with 221 additions and 363 deletions

View file

@ -194,6 +194,9 @@ VOID ExitBatch (LPTSTR msg)
if (bc->ffind)
cmd_free(bc->ffind);
UndoRedirection(bc->RedirList, NULL);
FreeRedirection(bc->RedirList);
/* Preserve echo state across batch calls */
bEcho = bc->bEcho;
@ -248,9 +251,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
n->prev = bc;
bc = n;
bc->In[0] = _T('\0');
bc->Out[0] = _T('\0');
bc->Err[0] = _T('\0');
bc->RedirList = NULL;
}
else if (bc->hBatchFile != INVALID_HANDLE_VALUE)
{
@ -263,7 +264,7 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
cmd_free (bc->raw_params);
}
GetFullPathName(fullname, sizeof(bc->BatchFilePath), bc->BatchFilePath, &tmp);
GetFullPathName(fullname, sizeof(bc->BatchFilePath) / sizeof(TCHAR), bc->BatchFilePath, &tmp);
*tmp = '\0';
bc->hBatchFile = hFile;
@ -300,17 +301,23 @@ BOOL Batch (LPTSTR fullname, LPTSTR firstword, LPTSTR param)
return TRUE;
}
VOID AddBatchRedirection(TCHAR * ifn, TCHAR * ofn, TCHAR * efn)
VOID AddBatchRedirection(REDIRECTION **RedirList)
{
REDIRECTION **ListEnd;
if(!bc)
return;
if(_tcslen(ifn))
_tcscpy(bc->In,ifn);
if(_tcslen(ofn))
_tcscpy(bc->Out,ofn);
if(_tcslen(efn))
_tcscpy(bc->Err,efn);
/* Prepend the list to the batch context's list */
ListEnd = RedirList;
while (*ListEnd)
ListEnd = &(*ListEnd)->Next;
*ListEnd = bc->RedirList;
bc->RedirList = *RedirList;
/* Null out the pointer so that the list will not be cleared prematurely.
* These redirections should persist until the batch file exits. */
*RedirList = NULL;
}
/*