Alexandre Julliard : ntdll: Disallow relative paths in wine_unix_to_nt_file_name(), handle them in the caller.

Alexandre Julliard julliard at winehq.org
Wed Jul 8 15:34:35 CDT 2020


Module: wine
Branch: master
Commit: 49fcd632e4b512421810ec4e35dc455b3f7697d3
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=49fcd632e4b512421810ec4e35dc455b3f7697d3

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Jul  8 13:53:14 2020 +0200

ntdll: Disallow relative paths in wine_unix_to_nt_file_name(), handle them in the caller.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/kernel32/path.c | 18 ++++++++++++++++--
 dlls/ntdll/path.c    | 17 ++---------------
 2 files changed, 18 insertions(+), 17 deletions(-)

diff --git a/dlls/kernel32/path.c b/dlls/kernel32/path.c
index d0f27d3359..33c39865b9 100644
--- a/dlls/kernel32/path.c
+++ b/dlls/kernel32/path.c
@@ -301,10 +301,24 @@ WCHAR * CDECL wine_get_dos_file_name( LPCSTR str )
 {
     UNICODE_STRING nt_name;
     ANSI_STRING unix_name;
+    NTSTATUS status;
+    WCHAR *buffer;
     DWORD len;
 
-    RtlInitAnsiString( &unix_name, str );
-    if (!set_ntstatus( wine_unix_to_nt_file_name( &unix_name, &nt_name ))) return NULL;
+    if (str[0] != '/')  /* relative path name */
+    {
+        len = strlen( str ) + 1;
+        if (!(buffer = RtlAllocateHeap( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return NULL;
+        MultiByteToWideChar( CP_UNIXCP, 0, str, len, buffer, len );
+        status = RtlDosPathNameToNtPathName_U_WithStatus( buffer, &nt_name, NULL, NULL );
+        RtlFreeHeap( GetProcessHeap(), 0, buffer );
+    }
+    else
+    {
+        RtlInitAnsiString( &unix_name, str );
+        status = wine_unix_to_nt_file_name( &unix_name, &nt_name );
+    }
+    if (!set_ntstatus( status )) return NULL;
     if (nt_name.Buffer[5] == ':')
     {
         /* get rid of the \??\ prefix */
diff --git a/dlls/ntdll/path.c b/dlls/ntdll/path.c
index c22189a7e7..fb85942eca 100644
--- a/dlls/ntdll/path.c
+++ b/dlls/ntdll/path.c
@@ -891,23 +891,10 @@ NTSTATUS WINAPI RtlSetCurrentDirectory_U(const UNICODE_STRING* dir)
  */
 NTSTATUS CDECL wine_unix_to_nt_file_name( const ANSI_STRING *name, UNICODE_STRING *nt )
 {
-    unsigned int lenW, lenA = name->Length;
+    unsigned int lenA = name->Length;
     const char *path = name->Buffer;
 
     if (!lenA) return STATUS_INVALID_PARAMETER;
-
-    if (path[0] != '/')  /* relative path name */
-    {
-        WCHAR *tmp;
-        NTSTATUS status;
-
-        if (!(tmp = RtlAllocateHeap( GetProcessHeap(), 0, (lenA + 1) * sizeof(WCHAR) )))
-            return STATUS_NO_MEMORY;
-        lenW = ntdll_umbstowcs( path, lenA, tmp, lenA );
-        tmp[lenW] = 0;
-        status = RtlDosPathNameToNtPathName_U_WithStatus( tmp, nt, NULL, NULL );
-        RtlFreeHeap( GetProcessHeap(), 0, tmp );
-        return status;
-    }
+    if (path[0] != '/') return STATUS_INVALID_PARAMETER; /* relative path not supported */
     return unix_funcs->unix_to_nt_file_name( name, nt );
 }




More information about the wine-cvs mailing list