Removed some error-prone bit-fiddling.

svn path=/trunk/; revision=3821
This commit is contained in:
Eric Kohl 2002-12-04 20:39:03 +00:00
parent e51ba71a9b
commit 2aacb78c3e

View file

@ -45,7 +45,9 @@ CmiObjectParse(PVOID ParsedObject,
PKEY_CELL SubKeyCell; PKEY_CELL SubKeyCell;
CHAR cPath[MAX_PATH]; CHAR cPath[MAX_PATH];
NTSTATUS Status; NTSTATUS Status;
PWSTR end; PWSTR StartPtr;
PWSTR EndPtr;
ULONG Length;
UNICODE_STRING LinkPath; UNICODE_STRING LinkPath;
UNICODE_STRING TargetPath; UNICODE_STRING TargetPath;
@ -63,22 +65,20 @@ CmiObjectParse(PVOID ParsedObject,
DPRINT("Path '%S'\n", *Path); DPRINT("Path '%S'\n", *Path);
if ((*Path[0]) == '\\') /* Extract relevant path name */
{ StartPtr = *Path;
end = wcschr((*Path) + 1, '\\'); if (*StartPtr == L'\\')
if (end != NULL) StartPtr++;
*end = 0;
wcstombs(cPath, (*Path) + 1, wcslen((*Path) + 1)); EndPtr = wcschr(StartPtr, L'\\');
cPath[wcslen((*Path) + 1)] = 0; if (EndPtr != NULL)
} Length = ((PCHAR)EndPtr - (PCHAR)StartPtr) / sizeof(WCHAR);
else else
{ Length = wcslen(StartPtr);
end = wcschr((*Path), '\\');
if (end != NULL) wcstombs(cPath, StartPtr, Length);
*end = 0; cPath[Length] = 0;
wcstombs(cPath, (*Path), wcslen((*Path)));
cPath[wcslen((*Path))] = 0;
}
FoundObject = CmiScanKeyList(ParsedKey, cPath, Attributes); FoundObject = CmiScanKeyList(ParsedKey, cPath, Attributes);
if (FoundObject == NULL) if (FoundObject == NULL)
@ -92,15 +92,11 @@ CmiObjectParse(PVOID ParsedObject,
Attributes); Attributes);
if (!NT_SUCCESS(Status) || (SubKeyCell == NULL)) if (!NT_SUCCESS(Status) || (SubKeyCell == NULL))
{ {
if (end != NULL)
{
*end = '\\';
}
return(STATUS_UNSUCCESSFUL); return(STATUS_UNSUCCESSFUL);
} }
if ((SubKeyCell->Type == REG_LINK_KEY_CELL_TYPE) && if ((SubKeyCell->Type == REG_LINK_KEY_CELL_TYPE) &&
!((Attributes & OBJ_OPENLINK) && (end == NULL))) !((Attributes & OBJ_OPENLINK) && (EndPtr == NULL) /*(end == NULL)*/))
{ {
RtlInitUnicodeString(&LinkPath, NULL); RtlInitUnicodeString(&LinkPath, NULL);
Status = CmiGetLinkTarget(ParsedKey->RegistryHive, Status = CmiGetLinkTarget(ParsedKey->RegistryHive,
@ -112,18 +108,17 @@ CmiObjectParse(PVOID ParsedObject,
/* build new FullPath for reparsing */ /* build new FullPath for reparsing */
TargetPath.MaximumLength = LinkPath.MaximumLength; TargetPath.MaximumLength = LinkPath.MaximumLength;
if (end != NULL) if (EndPtr != NULL)
{ {
*end = '\\'; TargetPath.MaximumLength += (wcslen(EndPtr) * sizeof(WCHAR));
TargetPath.MaximumLength += (wcslen(end) * sizeof(WCHAR)); }
}
TargetPath.Length = TargetPath.MaximumLength - sizeof(WCHAR); TargetPath.Length = TargetPath.MaximumLength - sizeof(WCHAR);
TargetPath.Buffer = ExAllocatePool(NonPagedPool, TargetPath.Buffer = ExAllocatePool(NonPagedPool,
TargetPath.MaximumLength); TargetPath.MaximumLength);
wcscpy(TargetPath.Buffer, LinkPath.Buffer); wcscpy(TargetPath.Buffer, LinkPath.Buffer);
if (end != NULL) if (EndPtr != NULL)
{ {
wcscat(TargetPath.Buffer, end); wcscat(TargetPath.Buffer, EndPtr);
} }
RtlFreeUnicodeString(FullPath); RtlFreeUnicodeString(FullPath);
@ -166,7 +161,7 @@ CmiObjectParse(PVOID ParsedObject,
else else
{ {
if ((FoundObject->KeyCell->Type == REG_LINK_KEY_CELL_TYPE) && if ((FoundObject->KeyCell->Type == REG_LINK_KEY_CELL_TYPE) &&
!((Attributes & OBJ_OPENLINK) && (end == NULL))) !((Attributes & OBJ_OPENLINK) && (EndPtr == NULL)/*(end == NULL)*/))
{ {
DPRINT("Found link\n"); DPRINT("Found link\n");
@ -180,18 +175,17 @@ CmiObjectParse(PVOID ParsedObject,
/* build new FullPath for reparsing */ /* build new FullPath for reparsing */
TargetPath.MaximumLength = LinkPath.MaximumLength; TargetPath.MaximumLength = LinkPath.MaximumLength;
if (end != NULL) if (EndPtr != NULL)
{ {
*end = '\\'; TargetPath.MaximumLength += (wcslen(EndPtr) * sizeof(WCHAR));
TargetPath.MaximumLength += (wcslen(end) * sizeof(WCHAR)); }
}
TargetPath.Length = TargetPath.MaximumLength - sizeof(WCHAR); TargetPath.Length = TargetPath.MaximumLength - sizeof(WCHAR);
TargetPath.Buffer = ExAllocatePool(NonPagedPool, TargetPath.Buffer = ExAllocatePool(NonPagedPool,
TargetPath.MaximumLength); TargetPath.MaximumLength);
wcscpy(TargetPath.Buffer, LinkPath.Buffer); wcscpy(TargetPath.Buffer, LinkPath.Buffer);
if (end != NULL) if (EndPtr != NULL)
{ {
wcscat(TargetPath.Buffer, end); wcscat(TargetPath.Buffer, EndPtr);
} }
RtlFreeUnicodeString(FullPath); RtlFreeUnicodeString(FullPath);
@ -226,15 +220,7 @@ CmiObjectParse(PVOID ParsedObject,
} }
#endif #endif
if (end != NULL) *Path = EndPtr;
{
*end = '\\';
*Path = end;
}
else
{
*Path = NULL;
}
VERIFY_KEY_OBJECT(FoundObject); VERIFY_KEY_OBJECT(FoundObject);