Re: [PATCH 1/6] msvcrt: Use LOCK_ENV locking in _chdrive and do validatation of input argument.
Kai Tietz <ktietz70(a)googlemail.com> writes:
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c index 44802b3..3b9e3c7 100644 --- a/dlls/msvcrt/dir.c +++ b/dlls/msvcrt/dir.c @@ -365,14 +365,25 @@ 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; }
Please add test cases at least for the error values. -- Alexandre Julliard julliard(a)winehq.org
2013/8/16 Alexandre Julliard <julliard(a)winehq.org>:
Kai Tietz <ktietz70(a)googlemail.com> writes:
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c index 44802b3..3b9e3c7 100644 --- a/dlls/msvcrt/dir.c +++ b/dlls/msvcrt/dir.c @@ -365,14 +365,25 @@ 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; }
Please add test cases at least for the error values.
-- Alexandre Julliard julliard(a)winehq.org
Ok, adjusted patch attached. Regards, Kai
Kai Tietz <ktietz70(a)googlemail.com> writes:
2013/8/16 Alexandre Julliard <julliard(a)winehq.org>:
Kai Tietz <ktietz70(a)googlemail.com> writes:
diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c index 44802b3..3b9e3c7 100644 --- a/dlls/msvcrt/dir.c +++ b/dlls/msvcrt/dir.c @@ -365,14 +365,25 @@ 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; }
Please add test cases at least for the error values.
-- Alexandre Julliard julliard(a)winehq.org
Ok, adjusted patch attached.
Please send all patches to wine-patches otherwise they don't go into the patch queue. -- Alexandre Julliard julliard(a)winehq.org
participants (2)
-
Alexandre Julliard -
Kai Tietz