fixed possible buffer overflow bug: pass correct buffer length (in characters, not bytes) to FileGetString()

svn path=/trunk/; revision=18187
This commit is contained in:
Thomas Bluemel 2005-10-01 12:21:55 +00:00
parent 580e685078
commit 0f55e53480
3 changed files with 5 additions and 6 deletions

View file

@ -408,7 +408,7 @@ LPTSTR ReadBatchLine (LPBOOL bLocalEcho)
return textline;
}
if (!FileGetString (bc->hBatchFile, textline, sizeof (textline)))
if (!FileGetString (bc->hBatchFile, textline, sizeof (textline) / sizeof (textline[0])))
{
#ifdef _DEBUG
DebugPrintf (_T("ReadBatchLine(): Reached EOF!\n"));

View file

@ -85,7 +85,7 @@ INT cmd_goto (LPTSTR cmd, LPTSTR param)
/* jump to begin of the file */
SetFilePointer (bc->hBatchFile, 0, &lNewPosHigh, FILE_BEGIN);
while (FileGetString (bc->hBatchFile, textline, sizeof(textline)))
while (FileGetString (bc->hBatchFile, textline, sizeof(textline) / sizeof(textline[0])))
{
int pos;
int size;

View file

@ -381,13 +381,12 @@ BOOL FileGetString (HANDLE hFile, LPTSTR lpBuffer, INT nBufferLength)
while ((--nBufferLength > 0) &&
ReadFile(hFile, &ch, 1, &dwRead, NULL) && dwRead)
{
if ((ch == '\n') || (ch == '\r'))
lpString[len++] = ch;
if ((ch == '\n') || (ch == '\r'))
{
/* read it*/
lpString[len++] = ch;
/* break at new line*/
break;
}
lpString[len++] = ch;
}
if (!dwRead && !len)