[PATCH] Make cu_compare_ref() also compare the actual classname of the ref and inst

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1194548973 28800 # Node ID a55a0f630c034ac5ed76211b8459ae1e4fdc56ae # Parent 41c761dba6a6268da6fdb9a89c1cc6f959870aac Make cu_compare_ref() also compare the actual classname of the ref and inst ...and change STREQ to STREQC, per Heidi's suggestion. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 41c761dba6a6 -r a55a0f630c03 instance_util.c --- a/instance_util.c Thu Nov 08 10:28:41 2007 -0800 +++ b/instance_util.c Thu Nov 08 11:09:33 2007 -0800 @@ -78,7 +78,7 @@ static bool _compare_data(const CMPIData const char *as = CMGetCharPtr(a->value.string); const char *bs = CMGetCharPtr(b->value.string); - return STREQ(as, bs); + return STREQC(as, bs); } else if (a->type & CMPI_INTEGER) { return memcmp(&a->value, &b->value, sizeof(a->value)) == 0; } @@ -86,6 +86,29 @@ static bool _compare_data(const CMPIData CU_DEBUG("Unhandled CMPI type: `%i'", a->type); return false; +} + +static bool _compare_classname(const CMPIObjectPath *ref, + const CMPIInstance *inst) +{ + const char *ref_cn; + const char *inst_cn; + CMPIObjectPath *op; + CMPIStatus s; + + op = CMGetObjectPath(inst, &s); + if ((op == NULL) || (s.rc != CMPI_RC_OK)) + return false; + + ref_cn = CLASSNAME(ref); + if (ref_cn == NULL) + return false; + + inst_cn = CLASSNAME(op); + if (inst_cn == NULL) + return false; + + return STREQC(inst_cn, ref_cn); } const char *cu_compare_ref(const CMPIObjectPath *ref, @@ -101,6 +124,9 @@ const char *cu_compare_ref(const CMPIObj CU_DEBUG("Unable to get key count"); return NULL; } + + if (!_compare_classname(ref, inst)) + return "CreationClassName"; for (i = 0; i < count; i++) { CMPIData kd, pd;

DS> # HG changeset patch DS> # User Dan Smith <danms@us.ibm.com> DS> # Date 1194548973 28800 DS> # Node ID a55a0f630c034ac5ed76211b8459ae1e4fdc56ae DS> # Parent 41c761dba6a6268da6fdb9a89c1cc6f959870aac DS> Make cu_compare_ref() also compare the actual classname of the ref and inst This makes cu_compare_ref() assist association providers in avoiding carefully crafted instances to fool the dispatch code. For example, in HostedResourcePool, it (now) uses cu_compare_ref() to make sure the client specified a valid HostSystem, but since ComputerSystem is a CIM_System, if you pass ComputerSystem.Name="<hostname_of_system>", HostedResourcePool would validate Name and proceed. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
This makes cu_compare_ref() assist association providers in avoiding carefully crafted instances to fool the dispatch code. For example, in HostedResourcePool, it (now) uses cu_compare_ref() to make sure the client specified a valid HostSystem, but since ComputerSystem is a CIM_System, if you pass ComputerSystem.Name="<hostname_of_system>", HostedResourcePool would validate Name and proceed.
A very good catch :) ! -- Regards Heidi Eckhart Software Engineer Linux Technology Center - Open Hypervisor heidieck@linux.vnet.ibm.com ************************************************** IBM Deutschland Entwicklung GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschaeftsfuehrung: Herbert Kircher Sitz der Gesellschaft: Boeblingen Registergericht: Amtsgericht Stuttgart, HRB 243294

Dan Smith wrote:
# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1194548973 28800 # Node ID a55a0f630c034ac5ed76211b8459ae1e4fdc56ae # Parent 41c761dba6a6268da6fdb9a89c1cc6f959870aac Make cu_compare_ref() also compare the actual classname of the ref and inst
...and change STREQ to STREQC, per Heidi's suggestion.
Signed-off-by: Dan Smith <danms@us.ibm.com> Nice - this is a good check. +1
-- Kaitlin Rupert IBM Linux Technology Center karupert@us.ibm.com
participants (3)
-
Dan Smith
-
Heidi Eckhart
-
Kaitlin Rupert