mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 18:35:41 +00:00
- Add a few parameters check
- Calculate resource list size with FIELD_OFFSET macro - Fix a big bug in IResourceList_fnAddEntryFromParent which didnt copy the untranslated resource list entry svn path=/trunk/; revision=42439
This commit is contained in:
parent
ba99294c86
commit
78f8e0a7c2
1 changed files with 57 additions and 45 deletions
|
@ -22,6 +22,7 @@ typedef struct CResourceList
|
||||||
POOL_TYPE PoolType;
|
POOL_TYPE PoolType;
|
||||||
PCM_RESOURCE_LIST TranslatedResourceList;
|
PCM_RESOURCE_LIST TranslatedResourceList;
|
||||||
PCM_RESOURCE_LIST UntranslatedResourceList;
|
PCM_RESOURCE_LIST UntranslatedResourceList;
|
||||||
|
ULONG NumberOfEntries;
|
||||||
} IResourceListImpl;
|
} IResourceListImpl;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -100,7 +101,7 @@ IResourceList_fnNumberOfEntries(IResourceList* iface)
|
||||||
|
|
||||||
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
||||||
|
|
||||||
return This->TranslatedResourceList->List[0].PartialResourceList.Count;
|
return This->NumberOfEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
ULONG
|
ULONG
|
||||||
|
@ -115,6 +116,12 @@ IResourceList_fnNumberOfEntriesOfType(
|
||||||
|
|
||||||
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
||||||
|
|
||||||
|
if (!This->TranslatedResourceList)
|
||||||
|
{
|
||||||
|
/* no resource list */
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* I guess the translated and untranslated lists will be same length? */
|
/* I guess the translated and untranslated lists will be same length? */
|
||||||
for (Index = 0; Index < This->TranslatedResourceList->List[0].PartialResourceList.Count; Index ++ )
|
for (Index = 0; Index < This->TranslatedResourceList->List[0].PartialResourceList.Count; Index ++ )
|
||||||
{
|
{
|
||||||
|
@ -144,6 +151,12 @@ IResourceList_fnFindTranslatedEntry(
|
||||||
|
|
||||||
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
||||||
|
|
||||||
|
if (!This->TranslatedResourceList)
|
||||||
|
{
|
||||||
|
/* no resource list */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (DescIndex = 0; DescIndex < This->TranslatedResourceList->List[0].PartialResourceList.Count; DescIndex ++ )
|
for (DescIndex = 0; DescIndex < This->TranslatedResourceList->List[0].PartialResourceList.Count; DescIndex ++ )
|
||||||
{
|
{
|
||||||
PartialDescriptor = &This->TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
|
PartialDescriptor = &This->TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
|
||||||
|
@ -175,6 +188,12 @@ IResourceList_fnFindUntranslatedEntry(
|
||||||
|
|
||||||
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
||||||
|
|
||||||
|
if (!This->UntranslatedResourceList)
|
||||||
|
{
|
||||||
|
/* no resource list */
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (DescIndex = 0; DescIndex < This->UntranslatedResourceList->List[0].PartialResourceList.Count; DescIndex ++ )
|
for (DescIndex = 0; DescIndex < This->UntranslatedResourceList->List[0].PartialResourceList.Count; DescIndex ++ )
|
||||||
{
|
{
|
||||||
PartialDescriptor = &This->UntranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
|
PartialDescriptor = &This->UntranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[DescIndex];
|
||||||
|
@ -200,17 +219,29 @@ IResourceList_fnAddEntry(
|
||||||
IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Untranslated)
|
IN PCM_PARTIAL_RESOURCE_DESCRIPTOR Untranslated)
|
||||||
{
|
{
|
||||||
PCM_RESOURCE_LIST NewUntranslatedResources, NewTranslatedResources;
|
PCM_RESOURCE_LIST NewUntranslatedResources, NewTranslatedResources;
|
||||||
ULONG NewTranslatedSize, NewUntranslatedSize;
|
ULONG NewTranslatedSize, NewUntranslatedSize, TranslatedSize, UntranslatedSize, ResourceCount;
|
||||||
IResourceListImpl * This = (IResourceListImpl*)iface;
|
IResourceListImpl * This = (IResourceListImpl*)iface;
|
||||||
|
|
||||||
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
||||||
|
|
||||||
NewTranslatedSize = sizeof(CM_RESOURCE_LIST) + This->TranslatedResourceList[0].List->PartialResourceList.Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
|
/* calculate translated resource list size */
|
||||||
|
ResourceCount = This->TranslatedResourceList->List[0].PartialResourceList.Count;
|
||||||
|
NewTranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount+1]);
|
||||||
|
TranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
|
||||||
|
|
||||||
|
|
||||||
NewTranslatedResources = AllocateItem(This->PoolType, NewTranslatedSize, TAG_PORTCLASS);
|
NewTranslatedResources = AllocateItem(This->PoolType, NewTranslatedSize, TAG_PORTCLASS);
|
||||||
if (!NewTranslatedResources)
|
if (!NewTranslatedResources)
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
|
|
||||||
NewUntranslatedSize = sizeof(CM_RESOURCE_LIST) + This->UntranslatedResourceList[0].List->PartialResourceList.Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
|
|
||||||
|
/* calculate untranslated resouce list size */
|
||||||
|
ResourceCount = This->UntranslatedResourceList->List[0].PartialResourceList.Count;
|
||||||
|
NewUntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount+1]);
|
||||||
|
UntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
|
||||||
|
|
||||||
|
|
||||||
|
/* allocate untranslated resource list size */
|
||||||
NewUntranslatedResources = AllocateItem(This->PoolType, NewUntranslatedSize, TAG_PORTCLASS);
|
NewUntranslatedResources = AllocateItem(This->PoolType, NewUntranslatedSize, TAG_PORTCLASS);
|
||||||
if (!NewUntranslatedResources)
|
if (!NewUntranslatedResources)
|
||||||
{
|
{
|
||||||
|
@ -218,35 +249,29 @@ IResourceList_fnAddEntry(
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
return STATUS_INSUFFICIENT_RESOURCES;
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlCopyMemory(NewTranslatedResources, This->TranslatedResourceList, sizeof(CM_RESOURCE_LIST));
|
/* now copy translated resource list */
|
||||||
if (This->TranslatedResourceList[0].List->PartialResourceList.Count > 1)
|
RtlMoveMemory(NewTranslatedResources, This->TranslatedResourceList, TranslatedSize);
|
||||||
{
|
RtlMoveMemory((PUCHAR)NewTranslatedResources + TranslatedSize, Translated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
|
||||||
RtlCopyMemory(&NewTranslatedResources->List[0].PartialResourceList.PartialDescriptors[0],
|
|
||||||
&This->TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[0],
|
|
||||||
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * This->TranslatedResourceList->List[0].PartialResourceList.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
RtlCopyMemory(&NewTranslatedResources->List[0].PartialResourceList.PartialDescriptors[This->TranslatedResourceList[0].List->PartialResourceList.Count], Translated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
|
/* now copy untranslated resource list */
|
||||||
|
RtlMoveMemory(NewUntranslatedResources, This->UntranslatedResourceList, UntranslatedSize);
|
||||||
RtlCopyMemory(NewUntranslatedResources, This->UntranslatedResourceList, sizeof(CM_RESOURCE_LIST));
|
RtlMoveMemory((PUCHAR)NewUntranslatedResources + UntranslatedSize, Untranslated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
|
||||||
if (This->UntranslatedResourceList[0].List->PartialResourceList.Count > 1)
|
|
||||||
{
|
|
||||||
RtlCopyMemory(&NewUntranslatedResources->List[0].PartialResourceList.PartialDescriptors[0],
|
|
||||||
&This->UntranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[0],
|
|
||||||
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * This->UntranslatedResourceList->List[0].PartialResourceList.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
RtlCopyMemory(&NewUntranslatedResources->List[0].PartialResourceList.PartialDescriptors[This->UntranslatedResourceList[0].List->PartialResourceList.Count], Untranslated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
|
|
||||||
|
|
||||||
|
/* free old lists */
|
||||||
FreeItem(This->TranslatedResourceList, TAG_PORTCLASS);
|
FreeItem(This->TranslatedResourceList, TAG_PORTCLASS);
|
||||||
FreeItem(This->UntranslatedResourceList, TAG_PORTCLASS);
|
FreeItem(This->UntranslatedResourceList, TAG_PORTCLASS);
|
||||||
|
|
||||||
|
/* store new lists */
|
||||||
This->UntranslatedResourceList = NewUntranslatedResources;
|
This->UntranslatedResourceList = NewUntranslatedResources;
|
||||||
This->TranslatedResourceList = NewTranslatedResources;
|
This->TranslatedResourceList = NewTranslatedResources;
|
||||||
|
|
||||||
|
/* increment descriptor count */
|
||||||
NewUntranslatedResources->List[0].PartialResourceList.Count++;
|
NewUntranslatedResources->List[0].PartialResourceList.Count++;
|
||||||
NewTranslatedResources->List[0].PartialResourceList.Count++;
|
NewTranslatedResources->List[0].PartialResourceList.Count++;
|
||||||
|
|
||||||
|
/* add entry count */
|
||||||
|
This->NumberOfEntries++;
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
return STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,37 +283,21 @@ IResourceList_fnAddEntryFromParent(
|
||||||
IN CM_RESOURCE_TYPE Type,
|
IN CM_RESOURCE_TYPE Type,
|
||||||
IN ULONG Index)
|
IN ULONG Index)
|
||||||
{
|
{
|
||||||
PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated;
|
PCM_PARTIAL_RESOURCE_DESCRIPTOR Translated, Untranslated;
|
||||||
PCM_RESOURCE_LIST NewTranslatedResources;
|
|
||||||
ULONG NewTranslatedSize;
|
|
||||||
IResourceListImpl * This = (IResourceListImpl*)iface;
|
|
||||||
|
|
||||||
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
ASSERT_IRQL_EQUAL(PASSIVE_LEVEL);
|
||||||
|
|
||||||
Translated = Parent->lpVtbl->FindTranslatedEntry(Parent, Type, Index);
|
Translated = Parent->lpVtbl->FindTranslatedEntry(Parent, Type, Index);
|
||||||
if (!Translated)
|
Untranslated = Parent->lpVtbl->FindUntranslatedEntry(Parent, Type, Index);
|
||||||
return STATUS_INVALID_PARAMETER;
|
|
||||||
|
|
||||||
NewTranslatedSize = sizeof(CM_RESOURCE_LIST) + This->TranslatedResourceList[0].List->PartialResourceList.Count * sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR);
|
if (Translated && Untranslated)
|
||||||
NewTranslatedResources = AllocateItem(This->PoolType, NewTranslatedSize, TAG_PORTCLASS);
|
|
||||||
if (!NewTranslatedResources)
|
|
||||||
return STATUS_INSUFFICIENT_RESOURCES;
|
|
||||||
|
|
||||||
RtlCopyMemory(NewTranslatedResources, This->TranslatedResourceList, sizeof(CM_RESOURCE_LIST));
|
|
||||||
if (This->TranslatedResourceList[0].List->PartialResourceList.Count > 1)
|
|
||||||
{
|
{
|
||||||
RtlCopyMemory(&NewTranslatedResources->List[0].PartialResourceList.PartialDescriptors[0],
|
/* add entry from parent */
|
||||||
&This->TranslatedResourceList->List[0].PartialResourceList.PartialDescriptors[0],
|
return iface->lpVtbl->AddEntry(iface, Translated, Untranslated);
|
||||||
sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR) * This->TranslatedResourceList->List[0].PartialResourceList.Count);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RtlCopyMemory(&NewTranslatedResources->List[0].PartialResourceList.PartialDescriptors[This->TranslatedResourceList[0].List->PartialResourceList.Count], Translated, sizeof(CM_PARTIAL_RESOURCE_DESCRIPTOR));
|
/* entry not found */
|
||||||
|
return STATUS_INVALID_PARAMETER;
|
||||||
FreeItem(This->TranslatedResourceList, TAG_PORTCLASS);
|
|
||||||
This->TranslatedResourceList = NewTranslatedResources;
|
|
||||||
NewTranslatedResources->List[0].PartialResourceList.Count++;
|
|
||||||
|
|
||||||
return STATUS_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PCM_RESOURCE_LIST
|
PCM_RESOURCE_LIST
|
||||||
|
@ -399,6 +408,9 @@ PcNewResourceList(
|
||||||
ResourceCount = TranslatedResourceList->List[0].PartialResourceList.Count;
|
ResourceCount = TranslatedResourceList->List[0].PartialResourceList.Count;
|
||||||
NewTranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
|
NewTranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
|
||||||
|
|
||||||
|
/* store resource count */
|
||||||
|
NewList->NumberOfEntries = ResourceCount;
|
||||||
|
|
||||||
/* calculate untranslated resouce list size */
|
/* calculate untranslated resouce list size */
|
||||||
ResourceCount = UntranslatedResourceList->List[0].PartialResourceList.Count;
|
ResourceCount = UntranslatedResourceList->List[0].PartialResourceList.Count;
|
||||||
NewUntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
|
NewUntranslatedSize = FIELD_OFFSET(CM_RESOURCE_LIST, List[0].PartialResourceList.PartialDescriptors[ResourceCount]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue