- Accept NULL Buffer/Size in RtlGetFullPathName_Ustr
- Fix NULL dereference in RtlGetFullPathName_UstrEx if no StaticString was given
- Various other corrections to path functions. 17 test failures fixed overall.

svn path=/trunk/; revision=56426
This commit is contained in:
Thomas Faber 2012-04-25 22:21:00 +00:00
parent c1dd858adc
commit 9a9ec7bb7c

View file

@ -57,20 +57,17 @@ RtlDetermineDosPathNameType_Ustr(IN PCUNICODE_STRING PathString)
PWCHAR Path; PWCHAR Path;
ULONG Chars; ULONG Chars;
/* Validate the input */
if (!PathString) return RtlPathTypeUnknown;
Path = PathString->Buffer; Path = PathString->Buffer;
Chars = PathString->Length / sizeof(WCHAR); Chars = PathString->Length / sizeof(WCHAR);
/* Return if there are no characters */ /* Return if there are no characters */
if (!Chars) return RtlPathTypeUnknown; if (!Chars) return RtlPathTypeRelative;
/* /*
* The algorithm is similar to RtlDetermineDosPathNameType_U but here we * The algorithm is similar to RtlDetermineDosPathNameType_U but here we
* actually check for the path length before touching the characters * actually check for the path length before touching the characters
*/ */
if ((Chars < 1) || (IS_PATH_SEPARATOR(Path[0]))) if (IS_PATH_SEPARATOR(Path[0]))
{ {
if ((Chars < 2) || !(IS_PATH_SEPARATOR(Path[1]))) return RtlPathTypeRooted; /* \x */ if ((Chars < 2) || !(IS_PATH_SEPARATOR(Path[1]))) return RtlPathTypeRooted; /* \x */
if ((Chars < 3) || ((Path[2] != L'.') && (Path[2] != L'?'))) return RtlPathTypeUncAbsolute;/* \\x */ if ((Chars < 3) || ((Path[2] != L'.') && (Path[2] != L'?'))) return RtlPathTypeUncAbsolute;/* \\x */
@ -80,9 +77,9 @@ RtlDetermineDosPathNameType_Ustr(IN PCUNICODE_STRING PathString)
} }
else else
{ {
if ((Chars < 2) || (!(Path[0]) || (Path[1] != L':'))) return RtlPathTypeRelative; /* x */ if ((Chars < 2) || (Path[1] != L':')) return RtlPathTypeRelative; /* x */
if ((Chars < 3) || (IS_PATH_SEPARATOR(Path[2]))) return RtlPathTypeDriveAbsolute; /* x:\ */ if ((Chars < 3) || !(IS_PATH_SEPARATOR(Path[2]))) return RtlPathTypeDriveRelative; /* x: */
return RtlPathTypeDriveRelative; /* x: */ return RtlPathTypeDriveAbsolute; /* x:\ */
} }
} }
@ -308,8 +305,7 @@ RtlGetFullPathName_Ustr(IN PUNICODE_STRING FileName,
/* Handle initial path type and failure case */ /* Handle initial path type and failure case */
*PathType = RtlPathTypeUnknown; *PathType = RtlPathTypeUnknown;
if (!(Size) || !(Buffer) || !(FileName) || if (!(FileName->Length) || (FileName->Buffer[0] == UNICODE_NULL)) return 0;
!(FileName->Length) || (FileName->Buffer[0] == UNICODE_NULL)) return 0;
/* Break filename into component parts */ /* Break filename into component parts */
FileNameBuffer = FileName->Buffer; FileNameBuffer = FileName->Buffer;
@ -737,9 +733,6 @@ RtlDoesFileExists_UstrEx(IN PCUNICODE_STRING FileName,
NTSTATUS Status; NTSTATUS Status;
FILE_BASIC_INFORMATION BasicInformation; FILE_BASIC_INFORMATION BasicInformation;
/* Validate the input */
if (!FileName) return FALSE;
/* Get the NT Path */ /* Get the NT Path */
Result = RtlDosPathNameToRelativeNtPathName_Ustr(FileName, Result = RtlDosPathNameToRelativeNtPathName_Ustr(FileName,
&NtPathName, &NtPathName,
@ -862,7 +855,7 @@ RtlGetLongestNtPathLength(VOID)
* This is, and has always been equal to, 269 characters, except in Wine * This is, and has always been equal to, 269 characters, except in Wine
* which claims this is 277. Go figure. * which claims this is 277. Go figure.
*/ */
return (MAX_PATH + RtlpDosDevicesUncPrefix.Length + sizeof(ANSI_NULL)); return MAX_PATH + RtlpDosDevicesUncPrefix.Length / sizeof(WCHAR) + sizeof(ANSI_NULL);
} }
/* /*
@ -874,9 +867,6 @@ RtlDetermineDosPathNameType_U(IN PCWSTR Path)
{ {
DPRINT("RtlDetermineDosPathNameType_U %S\n", Path); DPRINT("RtlDetermineDosPathNameType_U %S\n", Path);
/* Validate the input */
if (!Path) return RtlPathTypeUnknown;
/* Unlike the newer RtlDetermineDosPathNameType_U we assume 4 characters */ /* Unlike the newer RtlDetermineDosPathNameType_U we assume 4 characters */
if (IS_PATH_SEPARATOR(Path[0])) if (IS_PATH_SEPARATOR(Path[0]))
{ {
@ -1997,7 +1987,7 @@ Release:
Quickie: Quickie:
/* Free any buffers we should be freeing */ /* Free any buffers we should be freeing */
DPRINT("Status: %lx %S %S\n", Status, StaticBuffer, TempDynamicString.Buffer); DPRINT("Status: %lx %S %S\n", Status, StaticBuffer, TempDynamicString.Buffer);
if ((StaticBuffer) && (StaticBuffer != StaticString->Buffer)) if ((StaticString) && (StaticBuffer) && (StaticBuffer != StaticString->Buffer))
{ {
RtlpFreeMemory(StaticBuffer, TAG_USTR); RtlpFreeMemory(StaticBuffer, TAG_USTR);
} }