mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 17:05:45 +00:00
[KERNEL32] Check NtQueryInformationFile succeed before using its return. Also fix coding style
CID 512966
This commit is contained in:
parent
361664d57f
commit
19f1cd78c1
1 changed files with 77 additions and 57 deletions
|
@ -329,65 +329,85 @@ SetFilePointerEx(HANDLE hFile,
|
||||||
PLARGE_INTEGER lpNewFilePointer,
|
PLARGE_INTEGER lpNewFilePointer,
|
||||||
DWORD dwMoveMethod)
|
DWORD dwMoveMethod)
|
||||||
{
|
{
|
||||||
|
NTSTATUS Status;
|
||||||
|
IO_STATUS_BLOCK IoStatusBlock;
|
||||||
FILE_POSITION_INFORMATION FilePosition;
|
FILE_POSITION_INFORMATION FilePosition;
|
||||||
FILE_STANDARD_INFORMATION FileStandard;
|
FILE_STANDARD_INFORMATION FileStandard;
|
||||||
NTSTATUS errCode;
|
|
||||||
IO_STATUS_BLOCK IoStatusBlock;
|
|
||||||
|
|
||||||
if(IsConsoleHandle(hFile))
|
if (IsConsoleHandle(hFile))
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_INVALID_HANDLE);
|
BaseSetLastNTError(STATUS_INVALID_HANDLE);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(dwMoveMethod)
|
switch (dwMoveMethod)
|
||||||
{
|
{
|
||||||
case FILE_CURRENT:
|
case FILE_CURRENT:
|
||||||
NtQueryInformationFile(hFile,
|
{
|
||||||
&IoStatusBlock,
|
Status = NtQueryInformationFile(hFile, &IoStatusBlock,
|
||||||
&FilePosition,
|
&FilePosition,
|
||||||
sizeof(FILE_POSITION_INFORMATION),
|
sizeof(FILE_POSITION_INFORMATION),
|
||||||
FilePositionInformation);
|
FilePositionInformation);
|
||||||
FilePosition.CurrentByteOffset.QuadPart += liDistanceToMove.QuadPart;
|
if (!NT_SUCCESS(Status))
|
||||||
break;
|
{
|
||||||
case FILE_END:
|
BaseSetLastNTError(Status);
|
||||||
NtQueryInformationFile(hFile,
|
|
||||||
&IoStatusBlock,
|
|
||||||
&FileStandard,
|
|
||||||
sizeof(FILE_STANDARD_INFORMATION),
|
|
||||||
FileStandardInformation);
|
|
||||||
FilePosition.CurrentByteOffset.QuadPart =
|
|
||||||
FileStandard.EndOfFile.QuadPart + liDistanceToMove.QuadPart;
|
|
||||||
break;
|
|
||||||
case FILE_BEGIN:
|
|
||||||
FilePosition.CurrentByteOffset.QuadPart = liDistanceToMove.QuadPart;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SetLastError(ERROR_INVALID_PARAMETER);
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(FilePosition.CurrentByteOffset.QuadPart < 0)
|
FilePosition.CurrentByteOffset.QuadPart += liDistanceToMove.QuadPart;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case FILE_END:
|
||||||
|
{
|
||||||
|
Status = NtQueryInformationFile(hFile, &IoStatusBlock,
|
||||||
|
&FileStandard,
|
||||||
|
sizeof(FILE_STANDARD_INFORMATION),
|
||||||
|
FileStandardInformation);
|
||||||
|
if (!NT_SUCCESS(Status))
|
||||||
|
{
|
||||||
|
BaseSetLastNTError(Status);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
FilePosition.CurrentByteOffset.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)
|
||||||
{
|
{
|
||||||
SetLastError(ERROR_NEGATIVE_SEEK);
|
SetLastError(ERROR_NEGATIVE_SEEK);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
errCode = NtSetInformationFile(hFile,
|
Status = NtSetInformationFile(hFile, &IoStatusBlock, &FilePosition,
|
||||||
&IoStatusBlock,
|
|
||||||
&FilePosition,
|
|
||||||
sizeof(FILE_POSITION_INFORMATION),
|
sizeof(FILE_POSITION_INFORMATION),
|
||||||
FilePositionInformation);
|
FilePositionInformation);
|
||||||
if (!NT_SUCCESS(errCode))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
BaseSetLastNTError(errCode);
|
BaseSetLastNTError(Status);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpNewFilePointer)
|
if (lpNewFilePointer != NULL)
|
||||||
{
|
{
|
||||||
*lpNewFilePointer = FilePosition.CurrentByteOffset;
|
*lpNewFilePointer = FilePosition.CurrentByteOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue