From 49fcd632e4b512421810ec4e35dc455b3f7697d3 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 8 Jul 2020 13:53:14 +0200 Subject: [PATCH] ntdll: Disallow relative paths in wine_unix_to_nt_file_name(), handle them in the caller. Signed-off-by: Alexandre Julliard --- 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 d0f27d33594..33c39865b95 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 c22189a7e75..fb85942ecae 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 ); }