}
else
{
- /* Add the length of the PATH variable */
+ /* Add the length of the PATH variable unless it's empty */
ASSERT(!(EnvPath.Length & 1));
- PathLengthInBytes += (EnvPath.Length + sizeof(L';'));
+ if (EnvPath.Length)
+ {
+ /* Reserve space for the variable and a semicolon */
+ PathLengthInBytes += (EnvPath.Length + sizeof(L';'));
+ }
}
break;
BaseComputeProcessExePath(IN LPWSTR FullPath)
{
PBASE_SEARCH_PATH_TYPE PathOrder;
- DPRINT1("Computing EXE path: %wZ\n", FullPath);
+ DPRINT("Computing EXE path: %S\n", FullPath);
/* Check if we should use the current directory */
PathOrder = NeedCurrentDirectoryForExePathW(FullPath) ?
IN ULONG Length)
{
BOOLEAN HasExtension;
- WCHAR c;
+ UCHAR c;
NTSTATUS Status;
UNICODE_STRING UnicodeName;
ANSI_STRING AnsiName;
/* Initialize our two strings */
RtlInitEmptyAnsiString(&AnsiName, AnsiBuffer, MAX_PATH);
- RtlInitEmptyUnicodeString(&UnicodeName, Name, Length * sizeof(WCHAR));
+ RtlInitEmptyUnicodeString(&UnicodeName, Name, (USHORT)Length * sizeof(WCHAR));
UnicodeName.Length = UnicodeName.MaximumLength;
/* Now do the conversion */
/* Check what kind of path this is and how many slashes to skip */
switch (RtlDetermineDosPathNameType_U(Path))
{
+ case RtlPathTypeUncAbsolute:
+ case RtlPathTypeLocalDevice:
+ {
+ /* Keep going until we bypass the path indicators */
+ for (ReturnPath = Path + 2, i = 2; (i > 0) && (*ReturnPath); ReturnPath++)
+ {
+ /* We look for 2 slashes, so keep at it until we find them */
+ if ((*ReturnPath == L'\\') || (*ReturnPath == L'/')) i--;
+ }
+
+ return ReturnPath;
+ }
+
case RtlPathTypeDriveAbsolute:
return Path + 3;
case RtlPathTypeRootLocalDevice:
default:
return NULL;
-
- case RtlPathTypeUncAbsolute:
- case RtlPathTypeLocalDevice:
-
- /* Keep going until we bypass the path indicators */
- for (ReturnPath = Path + 2, i = 2; (i > 0) && (*ReturnPath); ReturnPath++)
- {
- /* We look for 2 slashes, so keep at it until we find them */
- if ((*ReturnPath == L'\\') || (*ReturnPath == L'/')) i--;
- }
-
- return ReturnPath;
}
}
ANSI_STRING AnsiDllDirectory;
ULONG Length;
- RtlInitEmptyAnsiString(&AnsiDllDirectory, lpBuffer, nBufferLength);
+ RtlInitEmptyAnsiString(&AnsiDllDirectory, lpBuffer, (USHORT)nBufferLength);
RtlEnterCriticalSection(&BaseDllDirectoryLock);
}
/* Set the path size now that we have it */
- PathString.MaximumLength = PathString.Length = LengthNeeded * sizeof(WCHAR);
+ PathString.MaximumLength = PathString.Length = (USHORT)LengthNeeded * sizeof(WCHAR);
/* Request SxS isolation from RtlDosSearchPath_Ustr */
Flags |= 1;
if (nBufferLength <= UNICODE_STRING_MAX_CHARS)
{
/* Add it into the string */
- CallerBuffer.MaximumLength = nBufferLength * sizeof(WCHAR);
+ CallerBuffer.MaximumLength = (USHORT)nBufferLength * sizeof(WCHAR);
}
else
{
if (!PathLength) goto Quickie;
- ShortPathUni.MaximumLength = PathLength * sizeof(WCHAR) + sizeof(UNICODE_NULL);
+ ShortPathUni.MaximumLength = (USHORT)PathLength * sizeof(WCHAR) + sizeof(UNICODE_NULL);
LongPathUni.Buffer = LongPath;
- LongPathUni.Length = PathLength * sizeof(WCHAR);
+ LongPathUni.Length = (USHORT)PathLength * sizeof(WCHAR);
Status = BasepUnicodeStringTo8BitString(&LongPathAnsi, &LongPathUni, TRUE);
if (!NT_SUCCESS(Status))
if (!PathLength) goto Quickie;
- LongPathUni.MaximumLength = PathLength * sizeof(WCHAR) + sizeof(UNICODE_NULL);
+ LongPathUni.MaximumLength = (USHORT)PathLength * sizeof(WCHAR) + sizeof(UNICODE_NULL);
ShortPathUni.Buffer = ShortPath;
- ShortPathUni.Length = PathLength * sizeof(WCHAR);
+ ShortPathUni.Length = (USHORT)PathLength * sizeof(WCHAR);
Status = BasepUnicodeStringTo8BitString(&ShortPathAnsi, &ShortPathUni, TRUE);
if (!NT_SUCCESS(Status))
ret++; /* add space for terminating 0 */
- if (count)
+ if (count >= ret)
{
lstrcpynW(path, full_tmp_path, count);
- if (count >= ret)
- ret--; /* return length without 0 */
- else if (count < 4)
- path[0] = 0; /* avoid returning ambiguous "X:" */
+ /* the remaining buffer must be zeroed up to 32766 bytes in XP or 32767
+ * bytes after it, we will assume the > XP behavior for now */
+ memset(path + ret, 0, (min(count, 32767) - ret) * sizeof(WCHAR));
+ ret--; /* return length without 0 */
+ }
+ else if (count)
+ {
+ /* the buffer must be cleared if contents will not fit */
+ memset(path, 0, count * sizeof(WCHAR));
}
DPRINT("GetTempPathW returning %u, %S\n", ret, path);
MaxLength = UNICODE_STRING_MAX_BYTES - 1;
}
- StaticString->Length = RtlGetCurrentDirectory_U(StaticString->MaximumLength,
- StaticString->Buffer);
+ StaticString->Length = (USHORT)RtlGetCurrentDirectory_U(StaticString->MaximumLength,
+ StaticString->Buffer);
Status = RtlUnicodeToMultiByteSize(&nBufferLength,
StaticString->Buffer,
StaticString->Length);
}
AnsiString.Buffer = lpBuffer;
- AnsiString.MaximumLength = MaxLength;
+ AnsiString.MaximumLength = (USHORT)MaxLength;
Status = BasepUnicodeStringTo8BitString(&AnsiString, StaticString, FALSE);
if (!NT_SUCCESS(Status))
{