[PATCH 0 of 2] HostSystem: validate client given object path

- patch 1 checks if getInstance incoming ref is valid - patch 2 updates validate_host_ref to use cmpiutil function to check input ref

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1201177348 -3600 # Node ID 4cbd5d50bee23b8cf6d08f5724aef04b011d2030 # Parent 70dedb925282ed3ceccf95872537204a1531c777 HostSystem: check if input ref is valid Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 70dedb925282 -r 4cbd5d50bee2 src/Virt_HostSystem.c --- a/src/Virt_HostSystem.c Thu Jan 24 12:56:45 2008 +0100 +++ b/src/Virt_HostSystem.c Thu Jan 24 13:22:28 2008 +0100 @@ -112,19 +112,35 @@ CMPIStatus get_host_cs(const CMPIBroker static CMPIStatus return_host_cs(const CMPIObjectPath *reference, const CMPIResult *results, - int name_only) + int name_only, + bool getInstance) { CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *instance; s = get_host_cs(_BROKER, reference, &instance); - if (s.rc != CMPI_RC_OK || instance == NULL) - goto out; + if (s.rc != CMPI_RC_OK) + goto out; + + if (instance == NULL) { + if (getInstance) + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance"); + goto out; + } + + if (getInstance) { + s = cu_validate_ref(_BROKER, reference, instance); + if (s.rc != CMPI_RC_OK) + goto out; + } if (name_only) cu_return_instance_name(results, instance); else CMReturnInstance(results, instance); + out: return s; } @@ -164,7 +180,7 @@ static CMPIStatus EnumInstanceNames(CMPI const CMPIResult *results, const CMPIObjectPath *reference) { - return return_host_cs(reference, results, 1); + return return_host_cs(reference, results, 1, false); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -174,7 +190,7 @@ static CMPIStatus EnumInstances(CMPIInst const char **properties) { - return return_host_cs(reference, results, 0); + return return_host_cs(reference, results, 0, false); } static CMPIStatus GetInstance(CMPIInstanceMI *self, @@ -183,7 +199,7 @@ static CMPIStatus GetInstance(CMPIInstan const CMPIObjectPath *reference, const char **properties) { - return return_host_cs(reference, results, 0); + return return_host_cs(reference, results, 0, true); } DEFAULT_CI();

Heidi Eckhart wrote:
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1201177348 -3600 # Node ID 4cbd5d50bee23b8cf6d08f5724aef04b011d2030 # Parent 70dedb925282ed3ceccf95872537204a1531c777 HostSystem: check if input ref is valid Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com>
diff -r 70dedb925282 -r 4cbd5d50bee2 src/Virt_HostSystem.c --- a/src/Virt_HostSystem.c Thu Jan 24 12:56:45 2008 +0100 +++ b/src/Virt_HostSystem.c Thu Jan 24 13:22:28 2008 +0100 @@ -112,19 +112,35 @@ CMPIStatus get_host_cs(const CMPIBroker
static CMPIStatus return_host_cs(const CMPIObjectPath *reference, const CMPIResult *results, - int name_only) + int name_only, + bool getInstance)
A bit nitpicky here, but I think here name_only is an int that's being use as a boolean, while getInstance is an actual boolean. I'm fine with doing things either way, but for the sake of consistency they should probably be the same. I'd vote for making name_only a bool. -- -Jay

JG> A bit nitpicky here, but I think here name_only is an int that's JG> being use as a boolean, while getInstance is an actual boolean. JG> I'm fine with doing things either way, but for the sake of JG> consistency they should probably be the same. I'd vote for making JG> name_only a bool. Agreed. She didn't add this, but while it's being modified it would be nice to get it changed. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
JG> A bit nitpicky here, but I think here name_only is an int that's JG> being use as a boolean, while getInstance is an actual boolean. JG> I'm fine with doing things either way, but for the sake of JG> consistency they should probably be the same. I'd vote for making JG> name_only a bool.
Agreed. She didn't add this, but while it's being modified it would be nice to get it changed.
Yea, sorry I forgot to add, "and I won't yell at you for making an 'unnecessary change' since the line is already being modified. :) -- -Jay

Jay Gagnon wrote:
Dan Smith wrote:
JG> A bit nitpicky here, but I think here name_only is an int that's JG> being use as a boolean, while getInstance is an actual boolean. JG> I'm fine with doing things either way, but for the sake of JG> consistency they should probably be the same. I'd vote for making JG> name_only a bool.
Agreed. She didn't add this, but while it's being modified it would be nice to get it changed.
Yea, sorry I forgot to add, "and I won't yell at you for making an 'unnecessary change' since the line is already being modified. :)
As Dan said some time ... "I should have know this" ;) ... hehe I will make the change. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1201177694 -3600 # Node ID dc5a3cf2e717e2630958454211bc7e0e4b8b2e94 # Parent 4cbd5d50bee23b8cf6d08f5724aef04b011d2030 HostSystem: Use cmpiutil function to validate incoming reference Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 4cbd5d50bee2 -r dc5a3cf2e717 src/Virt_HostSystem.c --- a/src/Virt_HostSystem.c Thu Jan 24 13:22:28 2008 +0100 +++ b/src/Virt_HostSystem.c Thu Jan 24 13:28:14 2008 +0100 @@ -41,16 +41,10 @@ CMPIStatus validate_host_ref(const CMPIB { CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *inst; - const char *prop; s = get_host_cs(broker, ref, &inst); - - prop = cu_compare_ref(ref, inst); - if (prop != NULL) { - cu_statusf(broker, &s, - CMPI_RC_ERR_NOT_FOUND, - "No such instance (%s)", prop); - } + if (inst != NULL) + s = cu_validate_ref(broker, ref, inst); return s; }
participants (4)
-
Dan Smith
-
Heidi Eckhart
-
Jay Gagnon
-
Kaitlin Rupert