Commit in reactos/lib/kernel32 on MAIN
file/file.c+59-91.54 -> 1.55
misc/console.c+5-111.74 -> 1.75
+64-20
2 modified files
1. properly check parameters in SetFilePointer(Ex)()
2. fixed several functions to fail if dealing with console handles

reactos/lib/kernel32/file
file.c 1.54 -> 1.55
diff -u -r1.54 -r1.55
--- file.c	25 May 2004 20:04:13 -0000	1.54
+++ file.c	28 May 2004 13:17:32 -0000	1.55
@@ -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 @@
 	       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 @@
    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 @@
      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 @@
 		 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 @@
      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 @@
    NTSTATUS errCode;
    IO_STATUS_BLOCK IoStatusBlock;
 
+   if(IsConsoleHandle(hFile))
+   {
+     SetLastError(ERROR_INVALID_HANDLE);
+     return FALSE;
+   }
+
    errCode = NtQueryInformationFile(hFile,
 				    &IoStatusBlock,
 				    &FileBasic,
@@ -1043,6 +1063,12 @@
    FILE_BASIC_INFORMATION FileBasic;
    NTSTATUS Status;
 
+   if(IsConsoleHandle(hFile))
+   {
+     SetLastError(ERROR_INVALID_HANDLE);
+     return FALSE;
+   }
+
    Status = NtQueryInformationFile(hFile,
 				   &IoStatusBlock,
 				   &FileBasic,
@@ -1078,6 +1104,12 @@
    IO_STATUS_BLOCK IoStatusBlock;
    NTSTATUS Status;
 
+   if(IsConsoleHandle(hFile))
+   {
+     SetLastError(ERROR_INVALID_HANDLE);
+     return FALSE;
+   }
+
    Status = NtQueryInformationFile(hFile,
 				   &IoStatusBlock,
 				   &FileBasic,
@@ -1127,6 +1159,12 @@
 	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 @@
   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 @@
   ANSI_STRING ShortNameA;
   UNICODE_STRING ShortName;
   
+  if(IsConsoleHandle(hFile))
+  {
+    SetLastError(ERROR_INVALID_HANDLE);
+    return FALSE;
+  }
+  
   if(!lpShortName)
   {
     SetLastError(ERROR_INVALID_PARAMETER);

reactos/lib/kernel32/misc
console.c 1.74 -> 1.75
diff -u -r1.74 -r1.75
--- console.c	14 Mar 2004 17:53:26 -0000	1.74
+++ console.c	28 May 2004 13:17:32 -0000	1.75
@@ -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,16 +1030,9 @@
 {
   PRTL_USER_PROCESS_PARAMETERS Ppb;
 
-  Ppb = NtCurrentPeb()->ProcessParameters;
+  /* no need to check if hHandle == INVALID_HANDLE_VALUE */
 
-  /* More checking needed? */
-  if (hHandle == INVALID_HANDLE_VALUE)
-    {
-      SetLastError (ERROR_INVALID_HANDLE);
-      return FALSE;
-    }
-
-  SetLastError(ERROR_SUCCESS); /* OK */
+  Ppb = NtCurrentPeb()->ProcessParameters;
 
   switch (nStdHandle)
     {
@@ -1056,7 +1049,8 @@
 	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;
 }
 
CVSspam 0.2.8