mirror of
https://github.com/reactos/reactos.git
synced 2024-12-27 17:44:45 +00:00
- Don't convert the device name, if the name is a NULL pointer (in QueryDosDeviceA).
- Convert the string in several steps, because the string may be longer than 32k characters (in QueryDosDeviceA). svn path=/trunk/; revision=18060
This commit is contained in:
parent
36b54a2e7c
commit
18494d1af0
1 changed files with 46 additions and 29 deletions
|
@ -96,51 +96,68 @@ QueryDosDeviceA(
|
||||||
UNICODE_STRING TargetPathU;
|
UNICODE_STRING TargetPathU;
|
||||||
ANSI_STRING TargetPathA;
|
ANSI_STRING TargetPathA;
|
||||||
DWORD Length;
|
DWORD Length;
|
||||||
|
DWORD CurrentLength;
|
||||||
|
PWCHAR Buffer;
|
||||||
|
|
||||||
if (!RtlCreateUnicodeStringFromAsciiz (&DeviceNameU,
|
if (lpDeviceName)
|
||||||
(LPSTR)lpDeviceName))
|
|
||||||
{
|
{
|
||||||
|
if (!RtlCreateUnicodeStringFromAsciiz (&DeviceNameU,
|
||||||
|
(LPSTR)lpDeviceName))
|
||||||
|
{
|
||||||
|
SetLastError (ERROR_NOT_ENOUGH_MEMORY);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
|
||||||
|
0,
|
||||||
|
ucchMax * sizeof(WCHAR));
|
||||||
|
if (Buffer == NULL)
|
||||||
|
{
|
||||||
|
if (lpDeviceName)
|
||||||
|
{
|
||||||
|
RtlFreeHeap (RtlGetProcessHeap (),
|
||||||
|
0,
|
||||||
|
DeviceNameU.Buffer);
|
||||||
|
}
|
||||||
SetLastError (ERROR_NOT_ENOUGH_MEMORY);
|
SetLastError (ERROR_NOT_ENOUGH_MEMORY);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
TargetPathU.Length = 0;
|
Length = QueryDosDeviceW (lpDeviceName ? DeviceNameU.Buffer : NULL,
|
||||||
TargetPathU.MaximumLength = (USHORT)ucchMax * sizeof(WCHAR);
|
Buffer,
|
||||||
TargetPathU.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
|
|
||||||
0,
|
|
||||||
TargetPathU.MaximumLength);
|
|
||||||
if (TargetPathU.Buffer == NULL)
|
|
||||||
{
|
|
||||||
SetLastError (ERROR_NOT_ENOUGH_MEMORY);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Length = QueryDosDeviceW (DeviceNameU.Buffer,
|
|
||||||
TargetPathU.Buffer,
|
|
||||||
ucchMax);
|
ucchMax);
|
||||||
if (Length != 0)
|
if (Length != 0)
|
||||||
{
|
{
|
||||||
TargetPathU.Length = Length * sizeof(WCHAR);
|
|
||||||
|
|
||||||
TargetPathA.Length = 0;
|
|
||||||
TargetPathA.MaximumLength = (USHORT)ucchMax;
|
|
||||||
TargetPathA.Buffer = lpTargetPath;
|
TargetPathA.Buffer = lpTargetPath;
|
||||||
|
TargetPathU.Buffer = Buffer;
|
||||||
|
ucchMax = Length;
|
||||||
|
|
||||||
RtlUnicodeStringToAnsiString (&TargetPathA,
|
while (ucchMax)
|
||||||
&TargetPathU,
|
{
|
||||||
FALSE);
|
CurrentLength = min (ucchMax, MAXUSHORT / 2);
|
||||||
|
TargetPathU.MaximumLength = TargetPathU.Length = CurrentLength * sizeof(WCHAR);
|
||||||
|
|
||||||
|
TargetPathA.Length = 0;
|
||||||
|
TargetPathA.MaximumLength = CurrentLength;
|
||||||
|
|
||||||
DPRINT ("TargetPathU: '%wZ'\n", &TargetPathU);
|
RtlUnicodeStringToAnsiString (&TargetPathA,
|
||||||
DPRINT ("TargetPathA: '%Z'\n", &TargetPathA);
|
&TargetPathU,
|
||||||
|
FALSE);
|
||||||
|
ucchMax -= CurrentLength;
|
||||||
|
TargetPathA.Buffer += TargetPathA.Length;
|
||||||
|
TargetPathU.Buffer += TargetPathU.Length / sizeof(WCHAR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlFreeHeap (RtlGetProcessHeap (),
|
RtlFreeHeap (RtlGetProcessHeap (),
|
||||||
0,
|
0,
|
||||||
TargetPathU.Buffer);
|
Buffer);
|
||||||
RtlFreeHeap (RtlGetProcessHeap (),
|
if (lpDeviceName)
|
||||||
0,
|
{
|
||||||
DeviceNameU.Buffer);
|
RtlFreeHeap (RtlGetProcessHeap (),
|
||||||
|
0,
|
||||||
|
DeviceNameU.Buffer);
|
||||||
|
}
|
||||||
return Length;
|
return Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue