Author: tfaber
Date: Sat Mar 4 15:17:30 2017
New Revision: 74052
URL:
http://svn.reactos.org/svn/reactos?rev=74052&view=rev
Log:
[NTOS:PNP]
- Use UNICODE_STRINGs in IopCreateDeviceInstancePath instead of messing around with unsafe
string functions and stack buffers
Modified:
trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c
Modified: trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.…
==============================================================================
--- trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/io/pnpmgr/pnpmgr.c [iso-8859-1] Sat Mar 4 15:17:30 2017
@@ -1879,9 +1879,8 @@
_Out_ PUNICODE_STRING InstancePath)
{
IO_STATUS_BLOCK IoStatusBlock;
- PWSTR DeviceId;
- PWSTR InstanceId;
- WCHAR InstancePathBuffer[MAX_PATH];
+ UNICODE_STRING DeviceId;
+ UNICODE_STRING InstanceId;
IO_STACK_LOCATION Stack;
NTSTATUS Status;
UNICODE_STRING ParentIdPrefix = { 0, 0, NULL };
@@ -1900,23 +1899,21 @@
return Status;
}
- /* Copy the device id string */
- DeviceId = (PWSTR)IoStatusBlock.Information;
- wcscpy(InstancePathBuffer, DeviceId);
+ /* Save the device id string */
+ RtlInitUnicodeString(&DeviceId, (PWSTR)IoStatusBlock.Information);
/*
* FIXME: Check for valid characters, if there is invalid characters
* then bugcheck.
*/
- ExFreePoolWithTag(DeviceId, 0);
-
DPRINT("Sending IRP_MN_QUERY_CAPABILITIES to device stack (after
enumeration)\n");
Status = IopQueryDeviceCapabilities(DeviceNode, &DeviceCapabilities);
if (!NT_SUCCESS(Status))
{
DPRINT1("IopQueryDeviceCapabilities() failed (Status 0x%08lx)\n",
Status);
+ RtlFreeUnicodeString(&DeviceId);
return Status;
}
@@ -1925,6 +1922,7 @@
{
/* FIXME: Cleanup device */
DeviceNode->Flags |= DNF_DISABLED;
+ RtlFreeUnicodeString(&DeviceId);
return STATUS_PLUGPLAY_NO_DEVICE;
}
else
@@ -1940,6 +1938,7 @@
if (!NT_SUCCESS(Status))
{
DPRINT1("IopGetParentIdPrefix() failed (Status 0x%08lx)\n",
Status);
+ RtlFreeUnicodeString(&DeviceId);
return Status;
}
}
@@ -1953,45 +1952,58 @@
&Stack);
if (NT_SUCCESS(Status))
{
- InstanceId = (PWSTR)IoStatusBlock.Information;
-
- /* Append the instance id string */
- wcscat(InstancePathBuffer, L"\\");
- if (ParentIdPrefix.Length > 0)
+ RtlInitUnicodeString(&InstanceId,
+ (PWSTR)IoStatusBlock.Information);
+
+ InstancePath->Length = 0;
+ InstancePath->MaximumLength = DeviceId.Length + sizeof(WCHAR) +
+ ParentIdPrefix.Length +
+ InstanceId.Length +
+ sizeof(UNICODE_NULL);
+ if (ParentIdPrefix.Length && InstanceId.Length)
{
- /* Add information from parent bus device to InstancePath */
- wcscat(InstancePathBuffer, ParentIdPrefix.Buffer);
- if (InstanceId && *InstanceId)
- {
- wcscat(InstancePathBuffer, L"&");
- }
+ InstancePath->MaximumLength += sizeof(WCHAR);
}
- if (InstanceId)
+
+ InstancePath->Buffer = ExAllocatePoolWithTag(PagedPool,
+ InstancePath->MaximumLength,
+ TAG_IO);
+ if (!InstancePath->Buffer)
{
- wcscat(InstancePathBuffer, InstanceId);
+ RtlFreeUnicodeString(&InstanceId);
+ RtlFreeUnicodeString(&ParentIdPrefix);
+ RtlFreeUnicodeString(&DeviceId);
+ return STATUS_INSUFFICIENT_RESOURCES;
}
+
+ /* Start with the device id */
+ RtlCopyUnicodeString(InstancePath, &DeviceId);
+ RtlAppendUnicodeToString(InstancePath, L"\\");
+
+ /* Add information from parent bus device to InstancePath */
+ RtlAppendUnicodeStringToString(InstancePath, &ParentIdPrefix);
+ if (ParentIdPrefix.Length && InstanceId.Length)
+ {
+ RtlAppendUnicodeToString(InstancePath, L"&");
+ }
+
+ /* Finally, add the id returned by the driver stack */
+ RtlAppendUnicodeStringToString(InstancePath, &InstanceId);
/*
* FIXME: Check for valid characters, if there is invalid characters
* then bugcheck
*/
- if (InstanceId)
- {
- ExFreePoolWithTag(InstanceId, 0);
- }
+ RtlFreeUnicodeString(&InstanceId);
+ RtlFreeUnicodeString(&DeviceId);
}
else
{
DPRINT("IopInitiatePnpIrp(BusQueryInstanceID) failed (Status %x)\n",
Status);
+ *InstancePath = DeviceId;
}
RtlFreeUnicodeString(&ParentIdPrefix);
-
- if (!RtlCreateUnicodeString(InstancePath, InstancePathBuffer))
- {
- DPRINT1("RtlCreateUnicodeString failed\n");
- return STATUS_INSUFFICIENT_RESOURCES;
- }
return STATUS_SUCCESS;
}