mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 09:25:10 +00:00
1. properly check parameters in SetFilePointer(Ex)()
2. fixed several functions to fail if dealing with console handles svn path=/trunk/; revision=9513
This commit is contained in:
parent
938ede25cd
commit
336746ec95
2 changed files with 64 additions and 20 deletions
|
@ -1,4 +1,4 @@
|
|||
/* $Id: file.c,v 1.54 2004/05/25 20:04:13 navaraf Exp $
|
||||
/* $Id: file.c,v 1.55 2004/05/28 13:17:32 weiden Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
|
@ -221,7 +221,7 @@ SetFilePointer(HANDLE hFile,
|
|||
DWORD dwMoveMethod)
|
||||
{
|
||||
FILE_POSITION_INFORMATION FilePosition;
|
||||
FILE_STANDARD_INFORMATION FileStandart;
|
||||
FILE_STANDARD_INFORMATION FileStandard;
|
||||
NTSTATUS errCode;
|
||||
IO_STATUS_BLOCK IoStatusBlock;
|
||||
LARGE_INTEGER Distance;
|
||||
|
@ -229,7 +229,11 @@ SetFilePointer(HANDLE hFile,
|
|||
DPRINT("SetFilePointer(hFile %x, lDistanceToMove %d, dwMoveMethod %d)\n",
|
||||
hFile,lDistanceToMove,dwMoveMethod);
|
||||
|
||||
/* FIXME - should fail if hFile is a console handle */
|
||||
if(IsConsoleHandle(hFile))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Distance.u.LowPart = lDistanceToMove;
|
||||
if (lpDistanceToMoveHigh)
|
||||
|
@ -258,15 +262,18 @@ SetFilePointer(HANDLE hFile,
|
|||
case FILE_END:
|
||||
NtQueryInformationFile(hFile,
|
||||
&IoStatusBlock,
|
||||
&FileStandart,
|
||||
&FileStandard,
|
||||
sizeof(FILE_STANDARD_INFORMATION),
|
||||
FileStandardInformation);
|
||||
FilePosition.CurrentByteOffset.QuadPart =
|
||||
FileStandart.EndOfFile.QuadPart + Distance.QuadPart;
|
||||
FileStandard.EndOfFile.QuadPart + Distance.QuadPart;
|
||||
break;
|
||||
case FILE_BEGIN:
|
||||
FilePosition.CurrentByteOffset.QuadPart = Distance.QuadPart;
|
||||
break;
|
||||
default:
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(FilePosition.CurrentByteOffset.QuadPart < 0)
|
||||
|
@ -305,11 +312,15 @@ SetFilePointerEx(HANDLE hFile,
|
|||
DWORD dwMoveMethod)
|
||||
{
|
||||
FILE_POSITION_INFORMATION FilePosition;
|
||||
FILE_STANDARD_INFORMATION FileStandart;
|
||||
FILE_STANDARD_INFORMATION FileStandard;
|
||||
NTSTATUS errCode;
|
||||
IO_STATUS_BLOCK IoStatusBlock;
|
||||
|
||||
/* FIXME - should fail if hFile is a console handle */
|
||||
if(IsConsoleHandle(hFile))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
switch(dwMoveMethod)
|
||||
{
|
||||
|
@ -324,15 +335,18 @@ SetFilePointerEx(HANDLE hFile,
|
|||
case FILE_END:
|
||||
NtQueryInformationFile(hFile,
|
||||
&IoStatusBlock,
|
||||
&FileStandart,
|
||||
&FileStandard,
|
||||
sizeof(FILE_STANDARD_INFORMATION),
|
||||
FileStandardInformation);
|
||||
FilePosition.CurrentByteOffset.QuadPart =
|
||||
FileStandart.EndOfFile.QuadPart + liDistanceToMove.QuadPart;
|
||||
FileStandard.EndOfFile.QuadPart + liDistanceToMove.QuadPart;
|
||||
break;
|
||||
case FILE_BEGIN:
|
||||
FilePosition.CurrentByteOffset.QuadPart = liDistanceToMove.QuadPart;
|
||||
break;
|
||||
default:
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(FilePosition.CurrentByteOffset.QuadPart < 0)
|
||||
|
@ -594,6 +608,12 @@ GetFileInformationByHandle(HANDLE hFile,
|
|||
NTSTATUS errCode;
|
||||
IO_STATUS_BLOCK IoStatusBlock;
|
||||
|
||||
if(IsConsoleHandle(hFile))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
errCode = NtQueryInformationFile(hFile,
|
||||
&IoStatusBlock,
|
||||
&FileBasic,
|
||||
|
@ -1043,6 +1063,12 @@ GetFileTime(HANDLE hFile,
|
|||
FILE_BASIC_INFORMATION FileBasic;
|
||||
NTSTATUS Status;
|
||||
|
||||
if(IsConsoleHandle(hFile))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = NtQueryInformationFile(hFile,
|
||||
&IoStatusBlock,
|
||||
&FileBasic,
|
||||
|
@ -1078,6 +1104,12 @@ SetFileTime(HANDLE hFile,
|
|||
IO_STATUS_BLOCK IoStatusBlock;
|
||||
NTSTATUS Status;
|
||||
|
||||
if(IsConsoleHandle(hFile))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Status = NtQueryInformationFile(hFile,
|
||||
&IoStatusBlock,
|
||||
&FileBasic,
|
||||
|
@ -1127,6 +1159,12 @@ SetEndOfFile(HANDLE hFile)
|
|||
FILE_POSITION_INFORMATION FilePosInfo;
|
||||
NTSTATUS Status;
|
||||
|
||||
if(IsConsoleHandle(hFile))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//get current position
|
||||
Status = NtQueryInformationFile(
|
||||
hFile,
|
||||
|
@ -1233,6 +1271,12 @@ SetFileShortNameW(
|
|||
IO_STATUS_BLOCK IoStatusBlock;
|
||||
PFILE_NAME_INFORMATION FileNameInformation;
|
||||
|
||||
if(IsConsoleHandle(hFile))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(!lpShortName)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
|
@ -1283,6 +1327,12 @@ SetFileShortNameA(
|
|||
ANSI_STRING ShortNameA;
|
||||
UNICODE_STRING ShortName;
|
||||
|
||||
if(IsConsoleHandle(hFile))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if(!lpShortName)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: console.c,v 1.74 2004/03/14 17:53:26 weiden Exp $
|
||||
/* $Id: console.c,v 1.75 2004/05/28 13:17:32 weiden Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
|
@ -1030,17 +1030,10 @@ SetStdHandle(DWORD nStdHandle,
|
|||
{
|
||||
PRTL_USER_PROCESS_PARAMETERS Ppb;
|
||||
|
||||
/* no need to check if hHandle == INVALID_HANDLE_VALUE */
|
||||
|
||||
Ppb = NtCurrentPeb()->ProcessParameters;
|
||||
|
||||
/* More checking needed? */
|
||||
if (hHandle == INVALID_HANDLE_VALUE)
|
||||
{
|
||||
SetLastError (ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
SetLastError(ERROR_SUCCESS); /* OK */
|
||||
|
||||
switch (nStdHandle)
|
||||
{
|
||||
case STD_INPUT_HANDLE:
|
||||
|
@ -1056,7 +1049,8 @@ SetStdHandle(DWORD nStdHandle,
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
SetLastError (ERROR_INVALID_PARAMETER);
|
||||
/* windows for whatever reason sets the last error to ERROR_INVALID_HANDLE here */
|
||||
SetLastError (ERROR_INVALID_HANDLE);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue