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

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-07-08 13:53:14 +02:00
parent 3aa4feb578
commit 49fcd632e4
2 changed files with 18 additions and 17 deletions

View File

@ -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 */

View File

@ -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 );
}