https://git.reactos.org/?p=reactos.git;a=commitdiff;h=02883d1c163c3e11c95ff…
commit 02883d1c163c3e11c95ffb873f071be384b13bda
Author: Jose Carlos Jesus <zecarlos1957(a)hotmail.com>
AuthorDate: Wed Sep 20 12:06:06 2023 -0400
Commit: GitHub <noreply(a)github.com>
CommitDate: Wed Sep 20 18:06:06 2023 +0200
[SDK:RTL] RtlpCallQueryRegistryRoutine(): Correctly set SpareData and SpareLength
(#5466)
SpareData and SpareLength need to be calculated correctly, as they are used
later in that function as well.
This allows to not overwrite Source UString when writing to Destination UString.
Fixes the problem described in the following JIRA issue, where services could
not start when installing ReactOS in a very-long-named directory.
CORE-18988
---
sdk/lib/rtl/registry.c | 54 +++++++++++++++++++++++++-------------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/sdk/lib/rtl/registry.c b/sdk/lib/rtl/registry.c
index 3172213265f..8beeb388ab8 100644
--- a/sdk/lib/rtl/registry.c
+++ b/sdk/lib/rtl/registry.c
@@ -196,36 +196,36 @@ RtlpCallQueryRegistryRoutine(IN PRTL_QUERY_REGISTRY_TABLE
QueryTable,
}
else
{
- /* Check if this isn't a direct return */
- if (!(QueryTable->Flags & RTL_QUERY_REGISTRY_DIRECT))
+ /* Check if we have length */
+ if (KeyValueInfo->DataLength)
{
- /* Check if we have length */
- if (KeyValueInfo->DataLength)
- {
- /* Increase the spare data */
- SpareData += KeyValueInfo->DataOffset +
- KeyValueInfo->DataLength;
- }
- else
- {
- /* Otherwise, the spare data only has the name data */
- SpareData += FIELD_OFFSET(KEY_VALUE_FULL_INFORMATION, Name) +
- KeyValueInfo->NameLength;
- }
+ /* Increase the spare data */
+ SpareData += KeyValueInfo->DataOffset +
+ KeyValueInfo->DataLength;
+ }
+ else
+ {
+ /* Otherwise, the spare data only has the name data */
+ SpareData += FIELD_OFFSET(KEY_VALUE_FULL_INFORMATION, Name) +
+ KeyValueInfo->NameLength;
+ }
- /* Align the pointer and get new size of spare data */
- SpareData = (PVOID)(((ULONG_PTR)SpareData + 7) & ~7);
- SpareLength = DataEnd - SpareData;
+ /* Align the pointer and get new size of spare data */
+ SpareData = (PVOID)(((ULONG_PTR)SpareData + 7) & ~7);
+ SpareLength = DataEnd - SpareData;
- /* Check if we have space to copy the data */
- RequiredLength = KeyValueInfo->NameLength + sizeof(UNICODE_NULL);
- if ((SpareData > DataEnd) || (SpareLength < RequiredLength))
- {
- /* Fail and return the missing length */
- *InfoSize = (ULONG)(SpareData - (PCHAR)KeyValueInfo) + RequiredLength;
- return STATUS_BUFFER_TOO_SMALL;
- }
+ /* Check if we have space to copy the data */
+ RequiredLength = KeyValueInfo->NameLength + sizeof(UNICODE_NULL);
+ if ((SpareData > DataEnd) || (SpareLength < RequiredLength))
+ {
+ /* Fail and return the missing length */
+ *InfoSize = (ULONG)(SpareData - (PCHAR)KeyValueInfo) + RequiredLength;
+ return STATUS_BUFFER_TOO_SMALL;
+ }
+ /* Check if this isn't a direct return */
+ if (!(QueryTable->Flags & RTL_QUERY_REGISTRY_DIRECT))
+ {
/* Copy the data and null-terminate it */
Name = (PWCHAR)SpareData;
RtlCopyMemory(Name, KeyValueInfo->Name, KeyValueInfo->NameLength);
@@ -330,7 +330,7 @@ RtlpCallQueryRegistryRoutine(IN PRTL_QUERY_REGISTRY_TABLE QueryTable,
RtlInitEmptyUnicodeString(&Source, Data, (USHORT)Length);
Source.Length = Source.MaximumLength - sizeof(UNICODE_NULL);
- /* Setup the desination string */
+ /* Setup the destination string */
RtlInitEmptyUnicodeString(&Destination, (PWCHAR)SpareData, 0);
/* Check if we're out of space */