mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
- fixed RegSetValueEx to take the null-terminating byte for strings into account when the caller forgot it
- capture the driver service name string in NtLoadDriver svn path=/trunk/; revision=14984
This commit is contained in:
parent
079656c5c4
commit
483c08b898
2 changed files with 104 additions and 73 deletions
|
@ -3003,14 +3003,21 @@ RegSetValueExA (HKEY hKey,
|
|||
pValueName = NULL;
|
||||
}
|
||||
|
||||
if ((dwType == REG_SZ) ||
|
||||
(dwType == REG_MULTI_SZ) ||
|
||||
(dwType == REG_EXPAND_SZ))
|
||||
if (((dwType == REG_SZ) ||
|
||||
(dwType == REG_MULTI_SZ) ||
|
||||
(dwType == REG_EXPAND_SZ)) &&
|
||||
(cbData != 0))
|
||||
{
|
||||
/* NT adds one if the caller forgot the NULL-termination character */
|
||||
if (lpData[cbData - 1] != '\0')
|
||||
{
|
||||
cbData++;
|
||||
}
|
||||
|
||||
RtlInitAnsiString (&AnsiString,
|
||||
NULL);
|
||||
AnsiString.Buffer = (PSTR)lpData;
|
||||
AnsiString.Length = cbData;
|
||||
AnsiString.Length = cbData - 1;
|
||||
AnsiString.MaximumLength = cbData;
|
||||
RtlAnsiStringToUnicodeString (&Data,
|
||||
&AnsiString,
|
||||
|
@ -3088,6 +3095,15 @@ RegSetValueExW (HKEY hKey,
|
|||
RtlInitUnicodeString (&ValueName, L"");
|
||||
}
|
||||
pValueName = &ValueName;
|
||||
|
||||
if (((dwType == REG_SZ) ||
|
||||
(dwType == REG_MULTI_SZ) ||
|
||||
(dwType == REG_EXPAND_SZ)) &&
|
||||
(cbData != 0) && (*(((PWCHAR)lpData) + (cbData / sizeof(WCHAR)) - 1) != L'\0'))
|
||||
{
|
||||
/* NT adds one if the caller forgot the NULL-termination character */
|
||||
cbData += sizeof(WCHAR);
|
||||
}
|
||||
|
||||
Status = NtSetValueKey (KeyHandle,
|
||||
pValueName,
|
||||
|
@ -3118,51 +3134,41 @@ RegSetValueA (HKEY hKey,
|
|||
LPCSTR lpData,
|
||||
DWORD cbData)
|
||||
{
|
||||
WCHAR SubKeyNameBuffer[MAX_PATH+1];
|
||||
UNICODE_STRING SubKeyName;
|
||||
UNICODE_STRING Data;
|
||||
ANSI_STRING AnsiString;
|
||||
LONG DataSize;
|
||||
LONG ErrorCode;
|
||||
LONG ret;
|
||||
HKEY hSubKey;
|
||||
|
||||
if (dwType != REG_SZ)
|
||||
{
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (lpSubKey != NULL && lpSubKey[0] != '\0')
|
||||
{
|
||||
ret = RegCreateKeyA(hKey,
|
||||
lpSubKey,
|
||||
&hSubKey);
|
||||
|
||||
if (lpData == NULL)
|
||||
{
|
||||
SetLastError (ERROR_INVALID_PARAMETER);
|
||||
return ERROR_INVALID_PARAMETER;
|
||||
}
|
||||
if (ret != ERROR_SUCCESS)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else
|
||||
hSubKey = hKey;
|
||||
|
||||
ret = RegSetValueExA(hSubKey,
|
||||
NULL,
|
||||
0,
|
||||
REG_SZ,
|
||||
lpData,
|
||||
strlen(lpData) + 1);
|
||||
|
||||
if (hSubKey != hKey)
|
||||
{
|
||||
RegCloseKey(hSubKey);
|
||||
}
|
||||
|
||||
RtlInitUnicodeString (&SubKeyName, NULL);
|
||||
RtlInitUnicodeString (&Data, NULL);
|
||||
if (lpSubKey != NULL && (strlen(lpSubKey) != 0))
|
||||
{
|
||||
RtlInitAnsiString (&AnsiString, (LPSTR)lpSubKey);
|
||||
SubKeyName.Buffer = &SubKeyNameBuffer[0];
|
||||
SubKeyName.MaximumLength = sizeof(SubKeyNameBuffer);
|
||||
RtlAnsiStringToUnicodeString (&SubKeyName, &AnsiString, FALSE);
|
||||
}
|
||||
|
||||
DataSize = cbData * sizeof(WCHAR);
|
||||
Data.MaximumLength = DataSize;
|
||||
Data.Buffer = RtlAllocateHeap (ProcessHeap,
|
||||
0,
|
||||
DataSize);
|
||||
if (Data.Buffer == NULL)
|
||||
{
|
||||
SetLastError (ERROR_OUTOFMEMORY);
|
||||
return ERROR_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
ErrorCode = RegSetValueW (hKey,
|
||||
(LPCWSTR)SubKeyName.Buffer,
|
||||
dwType,
|
||||
Data.Buffer,
|
||||
DataSize);
|
||||
|
||||
RtlFreeHeap (ProcessHeap,
|
||||
0,
|
||||
Data.Buffer);
|
||||
|
||||
return ErrorCode;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1311,7 +1311,7 @@ IopLoadDriver(PSERVICE Service)
|
|||
IopBootLog(&Service->ImagePath, NT_SUCCESS(Status) ? TRUE : FALSE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT("NtLoadDriver() failed (Status %lx)\n", Status);
|
||||
DPRINT("IopLoadDriver() failed (Status %lx)\n", Status);
|
||||
#if 0
|
||||
if (Service->ErrorControl == 1)
|
||||
{
|
||||
|
@ -1783,14 +1783,18 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
|||
RTL_QUERY_REGISTRY_TABLE QueryTable[3];
|
||||
UNICODE_STRING ImagePath;
|
||||
UNICODE_STRING ServiceName;
|
||||
UNICODE_STRING CapturedDriverServiceName;
|
||||
KPROCESSOR_MODE PreviousMode;
|
||||
NTSTATUS Status;
|
||||
ULONG Type;
|
||||
PDEVICE_NODE DeviceNode;
|
||||
PMODULE_OBJECT ModuleObject;
|
||||
PDRIVER_OBJECT DriverObject;
|
||||
LPWSTR Start;
|
||||
|
||||
DPRINT("NtLoadDriver('%wZ')\n", DriverServiceName);
|
||||
WCHAR *cur;
|
||||
|
||||
PAGED_CODE();
|
||||
|
||||
PreviousMode = KeGetPreviousMode();
|
||||
|
||||
/*
|
||||
* Check security privileges
|
||||
|
@ -1798,26 +1802,46 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
|||
|
||||
/* FIXME: Uncomment when privileges will be correctly implemented. */
|
||||
#if 0
|
||||
if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, KeGetPreviousMode()))
|
||||
if (!SeSinglePrivilegeCheck(SeLoadDriverPrivilege, PreviousMode))
|
||||
{
|
||||
DPRINT("Privilege not held\n");
|
||||
return STATUS_PRIVILEGE_NOT_HELD;
|
||||
}
|
||||
#endif
|
||||
|
||||
Status = RtlCaptureUnicodeString(&CapturedDriverServiceName,
|
||||
PreviousMode,
|
||||
PagedPool,
|
||||
FALSE,
|
||||
DriverServiceName);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return Status;
|
||||
}
|
||||
|
||||
DPRINT("NtLoadDriver('%wZ')\n", &CapturedDriverServiceName);
|
||||
|
||||
RtlInitUnicodeString(&ImagePath, NULL);
|
||||
|
||||
/*
|
||||
* Get the service name from the registry key name.
|
||||
*/
|
||||
ASSERT(CapturedDriverServiceName.Length >= sizeof(WCHAR));
|
||||
|
||||
Start = wcsrchr(DriverServiceName->Buffer, L'\\');
|
||||
if (Start == NULL)
|
||||
Start = DriverServiceName->Buffer;
|
||||
else
|
||||
Start++;
|
||||
|
||||
RtlInitUnicodeString(&ServiceName, Start);
|
||||
ServiceName = CapturedDriverServiceName;
|
||||
cur = CapturedDriverServiceName.Buffer + (CapturedDriverServiceName.Length / sizeof(WCHAR)) - 1;
|
||||
while (CapturedDriverServiceName.Buffer != cur)
|
||||
{
|
||||
if(*cur == L'\\')
|
||||
{
|
||||
ServiceName.Buffer = cur + 1;
|
||||
ServiceName.Length = CapturedDriverServiceName.Length -
|
||||
(USHORT)((ULONG_PTR)ServiceName.Buffer -
|
||||
(ULONG_PTR)CapturedDriverServiceName.Buffer);
|
||||
break;
|
||||
}
|
||||
cur--;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get service type.
|
||||
|
@ -1836,13 +1860,13 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
|||
QueryTable[1].EntryContext = &ImagePath;
|
||||
|
||||
Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
|
||||
DriverServiceName->Buffer, QueryTable, NULL, NULL);
|
||||
CapturedDriverServiceName.Buffer, QueryTable, NULL, NULL);
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT("RtlQueryRegistryValues() failed (Status %lx)\n", Status);
|
||||
RtlFreeUnicodeString(&ImagePath);
|
||||
return Status;
|
||||
goto ReleaseCapturedString;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1854,10 +1878,10 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
|||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT("IopNormalizeImagePath() failed (Status %x)\n", Status);
|
||||
return Status;
|
||||
goto ReleaseCapturedString;
|
||||
}
|
||||
|
||||
DPRINT("FullImagePath: '%S'\n", ImagePath.Buffer);
|
||||
DPRINT("FullImagePath: '%wZ'\n", &ImagePath);
|
||||
DPRINT("Type: %lx\n", Type);
|
||||
|
||||
/*
|
||||
|
@ -1868,7 +1892,8 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
|||
if (ModuleObject != NULL)
|
||||
{
|
||||
DPRINT("Image already loaded\n");
|
||||
return STATUS_IMAGE_ALREADY_LOADED;
|
||||
Status = STATUS_IMAGE_ALREADY_LOADED;
|
||||
goto ReleaseCapturedString;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1881,7 +1906,7 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
|||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
DPRINT("IopCreateDeviceNode() failed (Status %lx)\n", Status);
|
||||
return Status;
|
||||
goto ReleaseCapturedString;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1894,19 +1919,14 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
|||
{
|
||||
DPRINT("LdrLoadModule() failed (Status %lx)\n", Status);
|
||||
IopFreeDeviceNode(DeviceNode);
|
||||
return Status;
|
||||
goto ReleaseCapturedString;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set a service name for the device node
|
||||
*/
|
||||
|
||||
Start = wcsrchr(DriverServiceName->Buffer, L'\\');
|
||||
if (Start == NULL)
|
||||
Start = DriverServiceName->Buffer;
|
||||
else
|
||||
Start++;
|
||||
RtlpCreateUnicodeString(&DeviceNode->ServiceName, Start, NonPagedPool);
|
||||
RtlpCreateUnicodeString(&DeviceNode->ServiceName, ServiceName.Buffer, NonPagedPool);
|
||||
|
||||
/*
|
||||
* Initialize the driver module
|
||||
|
@ -1925,10 +1945,15 @@ NtLoadDriver(IN PUNICODE_STRING DriverServiceName)
|
|||
DPRINT("IopInitializeDriver() failed (Status %lx)\n", Status);
|
||||
LdrUnloadModule(ModuleObject);
|
||||
IopFreeDeviceNode(DeviceNode);
|
||||
return Status;
|
||||
goto ReleaseCapturedString;
|
||||
}
|
||||
|
||||
IopInitializeDevice(DeviceNode, DriverObject);
|
||||
|
||||
ReleaseCapturedString:
|
||||
RtlReleaseCapturedUnicodeString(&CapturedDriverServiceName,
|
||||
PreviousMode,
|
||||
FALSE);
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue