mirror of
https://github.com/reactos/reactos.git
synced 2025-03-30 17:10:22 +00:00
[NTOSKRNL]
- Fix NULL termination of strings in IoGetDeviceProperty - Fixes garbage displayed in the Enumerator field of the device manager property page svn path=/trunk/; revision=53232
This commit is contained in:
parent
704a9a3f49
commit
53e9ff45bf
1 changed files with 14 additions and 7 deletions
|
@ -3467,6 +3467,8 @@ IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject,
|
||||||
NTSTATUS Status = STATUS_BUFFER_TOO_SMALL;
|
NTSTATUS Status = STATUS_BUFFER_TOO_SMALL;
|
||||||
GUID BusTypeGuid;
|
GUID BusTypeGuid;
|
||||||
POBJECT_NAME_INFORMATION ObjectNameInfo = NULL;
|
POBJECT_NAME_INFORMATION ObjectNameInfo = NULL;
|
||||||
|
BOOLEAN NullTerminate = FALSE;
|
||||||
|
|
||||||
DPRINT("IoGetDeviceProperty(0x%p %d)\n", DeviceObject, DeviceProperty);
|
DPRINT("IoGetDeviceProperty(0x%p %d)\n", DeviceObject, DeviceProperty);
|
||||||
|
|
||||||
/* Assume failure */
|
/* Assume failure */
|
||||||
|
@ -3517,7 +3519,10 @@ IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject,
|
||||||
/* Get the name from the path */
|
/* Get the name from the path */
|
||||||
EnumeratorNameEnd = wcschr(DeviceInstanceName, OBJ_NAME_PATH_SEPARATOR);
|
EnumeratorNameEnd = wcschr(DeviceInstanceName, OBJ_NAME_PATH_SEPARATOR);
|
||||||
ASSERT(EnumeratorNameEnd);
|
ASSERT(EnumeratorNameEnd);
|
||||||
|
|
||||||
|
/* This string needs to be NULL-terminated */
|
||||||
|
NullTerminate = TRUE;
|
||||||
|
|
||||||
/* This is the format of the returned data */
|
/* This is the format of the returned data */
|
||||||
PIP_RETURN_DATA((EnumeratorNameEnd - DeviceInstanceName) * sizeof(WCHAR),
|
PIP_RETURN_DATA((EnumeratorNameEnd - DeviceInstanceName) * sizeof(WCHAR),
|
||||||
DeviceInstanceName);
|
DeviceInstanceName);
|
||||||
|
@ -3567,7 +3572,10 @@ IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject,
|
||||||
/* It's up to the caller to try again */
|
/* It's up to the caller to try again */
|
||||||
Status = STATUS_BUFFER_TOO_SMALL;
|
Status = STATUS_BUFFER_TOO_SMALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This string needs to be NULL-terminated */
|
||||||
|
NullTerminate = TRUE;
|
||||||
|
|
||||||
/* Return if successful */
|
/* Return if successful */
|
||||||
if (NT_SUCCESS(Status)) PIP_RETURN_DATA(ObjectNameInfo->Name.Length,
|
if (NT_SUCCESS(Status)) PIP_RETURN_DATA(ObjectNameInfo->Name.Length,
|
||||||
ObjectNameInfo->Name.Buffer);
|
ObjectNameInfo->Name.Buffer);
|
||||||
|
@ -3633,15 +3641,14 @@ IoGetDeviceProperty(IN PDEVICE_OBJECT DeviceObject,
|
||||||
else if (NT_SUCCESS(Status))
|
else if (NT_SUCCESS(Status))
|
||||||
{
|
{
|
||||||
/* We know up-front how much data to expect, check the caller's buffer */
|
/* We know up-front how much data to expect, check the caller's buffer */
|
||||||
*ResultLength = ReturnLength;
|
*ResultLength = ReturnLength + (NullTerminate ? sizeof(UNICODE_NULL) : 0);
|
||||||
if (ReturnLength <= BufferLength)
|
if (*ResultLength <= BufferLength)
|
||||||
{
|
{
|
||||||
/* Buffer is all good, copy the data */
|
/* Buffer is all good, copy the data */
|
||||||
RtlCopyMemory(PropertyBuffer, Data, ReturnLength);
|
RtlCopyMemory(PropertyBuffer, Data, ReturnLength);
|
||||||
|
|
||||||
/* Check for properties that require a null-terminated string */
|
/* Check if we need to NULL-terminate the string */
|
||||||
if ((DeviceProperty == DevicePropertyEnumeratorName) ||
|
if (NullTerminate)
|
||||||
(DeviceProperty == DevicePropertyPhysicalDeviceObjectName))
|
|
||||||
{
|
{
|
||||||
/* Terminate the string */
|
/* Terminate the string */
|
||||||
((PWCHAR)PropertyBuffer)[ReturnLength / sizeof(WCHAR)] = UNICODE_NULL;
|
((PWCHAR)PropertyBuffer)[ReturnLength / sizeof(WCHAR)] = UNICODE_NULL;
|
||||||
|
|
Loading…
Reference in a new issue