[patch 2 of 7]:0002-Lock-_chdrive-and-validate-input-argument

Kai Tietz ktietz70 at googlemail.com
Thu Dec 29 09:58:46 CST 2011


Hi,

the second patch of this series adds locking for _LOCK_ENV for chdrive
routine. (other places need this locking too AFAIR the documentation).
 Additionally it checks validity of input arguments and avoid
clobbering of GetLastError state for this case.

Regards,
Kai
-------------- next part --------------
From 5ed0399da23f706c56afe42a5d6c6c3d5a3859c7 Mon Sep 17 00:00:00 2001
From: Kai Tietz <ktietz70 at googlemail.com>
Date: Thu, 29 Dec 2011 14:44:40 +0100
Subject: Lock _chdrive and validate input argument.

---
 dlls/msvcrt/dir.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c
index 43afb2e..a65a401 100644
--- a/dlls/msvcrt/dir.c
+++ b/dlls/msvcrt/dir.c
@@ -345,14 +345,22 @@ int CDECL MSVCRT__chdrive(int newdrive)
 {
   WCHAR buffer[] = {'A', ':', 0};
 
+  if (newdrive < 1 || newdrive > 31)
+    {
+      *MSVCRT___doserrno () = ERROR_INVALID_DRIVE;
+      *MSVCRT__errno () = MSVCRT_EACCES;
+      return -1;
+    }
   buffer[0] += newdrive - 1;
-  if (!SetCurrentDirectoryW( buffer ))
+
+  _lock (_ENV_LOCK);
+  if (!SetCurrentDirectoryW (buffer))
   {
-    msvcrt_set_errno(GetLastError());
-    if (newdrive <= 0)
-      *MSVCRT__errno() = MSVCRT_EACCES;
+    msvcrt_set_errno (GetLastError ());
+    _unlock (_ENV_LOCK);
     return -1;
   }
+  _unlock (_ENV_LOCK);
   return 0;
 }
 
-- 
1.7.5.1


More information about the wine-patches mailing list