[Libvirt-cim] [PATCH] Add check to verify that sysname is not null

Chip Vincent cvincent at linux.vnet.ibm.com
Fri Mar 25 01:11:55 UTC 2011


+1 on these changes.

I think some additional error checkign might be a good idea. First, we 
should add some error checking to the lib function that initially 
gathers theses values and check that return code in providers. Second, 
setting a property to NULL and not setting a property are essentially 
the same thing in CIM. The property assumes a default value, which in 
most cases is NULL. I'll open a BZ for this and we can resolve that way.

Thanks!

On 03/23/2011 12:36 PM, Sharad Mishra wrote:
> # HG changeset patch
> # User Sharad Mishra<snmishra at us.ibm.com>
> # Date 1300897966 25200
> # Node ID 6e35991ef06d5f568bdfb199921e8591b1cf6452
> # Parent  62c565a5f71453b02cfcd1317e4a186f2ac1c519
> Add check to verify that sysname is not null.
>
> All string values like SystemCreationClass name and SystemName etc are not being checked for null before setting these properties.
>
> Signed-off-by: Sharad Mishra<snmishra at us.ibm.com>
>
> diff -r 62c565a5f714 -r 6e35991ef06d src/Virt_ConcreteComponent.c
> --- a/src/Virt_ConcreteComponent.c	Mon Mar 21 21:35:54 2011 -0400
> +++ b/src/Virt_ConcreteComponent.c	Wed Mar 23 09:32:46 2011 -0700
> @@ -85,9 +85,16 @@
>                   goto out;
>
>           CMAddKey(path, "CreationClassName", cn, CMPI_chars);
> -        CMAddKey(path, "SystemName", sys, CMPI_chars);
> -        CMAddKey(path, "SystemCreationClassName", syscc, CMPI_chars);
> -        CMAddKey(path, "DeviceID", bridge, CMPI_chars);
> +
> +        if (sys != NULL)
> +                CMAddKey(path, "SystemName", sys, CMPI_chars);
> +
> +        if (syscc != NULL)
> +                CMAddKey(path, "SystemCreationClassName",
> +                         syscc, CMPI_chars);
> +
> +        if (bridge != NULL)
> +                CMAddKey(path, "DeviceID", bridge, CMPI_chars);
>
>           inst = CBGetInstance(_BROKER, context, path, NULL, s);
>    out:
> diff -r 62c565a5f714 -r 6e35991ef06d src/Virt_ConsoleRedirectionService.c
> --- a/src/Virt_ConsoleRedirectionService.c	Mon Mar 21 21:35:54 2011 -0400
> +++ b/src/Virt_ConsoleRedirectionService.c	Wed Mar 23 09:32:46 2011 -0700
> @@ -67,11 +67,13 @@
>           CMSetProperty(inst, "Name",
>                         (CMPIValue *)"ConsoleRedirectionService", CMPI_chars);
>
> -        CMSetProperty(inst, "SystemName",
> -                      (CMPIValue *)name, CMPI_chars);
> +        if (name != NULL)
> +                CMSetProperty(inst, "SystemName",
> +                              (CMPIValue *)name, CMPI_chars);
>
> -        CMSetProperty(inst, "SystemCreationClassName",
> -                      (CMPIValue *)ccname, CMPI_chars);
> +        if (ccname != NULL)
> +                CMSetProperty(inst, "SystemCreationClassName",
> +                              (CMPIValue *)ccname, CMPI_chars);
>
>           array = CMNewArray(broker, 1, CMPI_uint16,&s);
>           if ((s.rc != CMPI_RC_OK) || CMIsNullObject(array))
> diff -r 62c565a5f714 -r 6e35991ef06d src/Virt_Device.c
> --- a/src/Virt_Device.c	Mon Mar 21 21:35:54 2011 -0400
> +++ b/src/Virt_Device.c	Wed Mar 23 09:32:46 2011 -0700
> @@ -344,8 +344,9 @@
>           if (conn) {
>                   char *sccn = NULL;
>                   sccn = get_typed_class(pfx_from_conn(conn), "ComputerSystem");
> -                CMSetProperty(instance, "SystemCreationClassName",
> -                              (CMPIValue *)sccn, CMPI_chars);
> +                if (sccn != NULL)
> +                        CMSetProperty(instance, "SystemCreationClassName",
> +                                      (CMPIValue *)sccn, CMPI_chars);
>                   free(sccn);
>           }
>
> diff -r 62c565a5f714 -r 6e35991ef06d src/Virt_KVMRedirectionSAP.c
> --- a/src/Virt_KVMRedirectionSAP.c	Mon Mar 21 21:35:54 2011 -0400
> +++ b/src/Virt_KVMRedirectionSAP.c	Wed Mar 23 09:32:46 2011 -0700
> @@ -76,17 +76,21 @@
>           pfx = class_prefix_name(CLASSNAME(ref));
>           sccn = get_typed_class(pfx, "ComputerSystem");
>
> -        CMSetProperty(inst, "Name",
> -                      (CMPIValue *)id, CMPI_chars);
> +        if (id != NULL)
> +                CMSetProperty(inst, "Name",
> +                              (CMPIValue *)id, CMPI_chars);
>
> -        CMSetProperty(inst, "SystemName",
> -                      (CMPIValue *)port->name, CMPI_chars);
> +        if (port->name != NULL)
> +                CMSetProperty(inst, "SystemName",
> +                              (CMPIValue *)port->name, CMPI_chars);
>
> -        CMSetProperty(inst, "SystemCreationClassName",
> -                      (CMPIValue *)sccn, CMPI_chars);
> +        if (sccn != NULL)
> +                CMSetProperty(inst, "SystemCreationClassName",
> +                              (CMPIValue *)sccn, CMPI_chars);
>
> -        CMSetProperty(inst, "ElementName",
> -                      (CMPIValue *)id, CMPI_chars);
> +        if (id != NULL)
> +                CMSetProperty(inst, "ElementName",
> +                              (CMPIValue *)id, CMPI_chars);
>
>           prop_val = (uint16_t)CIM_CRS_VNC;
>           CMSetProperty(inst, "KVMProtocol",
> diff -r 62c565a5f714 -r 6e35991ef06d src/Virt_ResourcePoolConfigurationService.c
> --- a/src/Virt_ResourcePoolConfigurationService.c	Mon Mar 21 21:35:54 2011 -0400
> +++ b/src/Virt_ResourcePoolConfigurationService.c	Wed Mar 23 09:32:46 2011 -0700
> @@ -1200,11 +1200,13 @@
>           CMSetProperty(inst, "Name",
>                         (CMPIValue *)"RPCS", CMPI_chars);
>
> -        CMSetProperty(inst, "SystemName",
> -                      (CMPIValue *)name, CMPI_chars);
> +        if (name != NULL)
> +                CMSetProperty(inst, "SystemName",
> +                              (CMPIValue *)name, CMPI_chars);
>
> -        CMSetProperty(inst, "SystemCreationClassName",
> -                      (CMPIValue *)ccname, CMPI_chars);
> +        if (ccname != NULL)
> +                CMSetProperty(inst, "SystemCreationClassName",
> +                              (CMPIValue *)ccname, CMPI_chars);
>
>           if (is_get_inst) {
>                   s = cu_validate_ref(broker, reference, inst);
> diff -r 62c565a5f714 -r 6e35991ef06d src/Virt_SwitchService.c
> --- a/src/Virt_SwitchService.c	Mon Mar 21 21:35:54 2011 -0400
> +++ b/src/Virt_SwitchService.c	Wed Mar 23 09:32:46 2011 -0700
> @@ -175,11 +175,13 @@
>                         (CMPIValue *)"Switch Virtualization Capabilities",
>                         CMPI_chars);
>
> -        CMSetProperty(inst, "SystemName",
> -                      (CMPIValue *)name, CMPI_chars);
> +        if (name != NULL)
> +                CMSetProperty(inst, "SystemName",
> +                              (CMPIValue *)name, CMPI_chars);
>
> -        CMSetProperty(inst, "SystemCreationClassName",
> -                      (CMPIValue *)ccname, CMPI_chars);
> +        if (ccname != NULL)
> +                CMSetProperty(inst, "SystemCreationClassName",
> +                              (CMPIValue *)ccname, CMPI_chars);
>
>    out:
>           return s;
> diff -r 62c565a5f714 -r 6e35991ef06d src/Virt_VSMigrationService.c
> --- a/src/Virt_VSMigrationService.c	Mon Mar 21 21:35:54 2011 -0400
> +++ b/src/Virt_VSMigrationService.c	Wed Mar 23 09:32:46 2011 -0700
> @@ -1698,11 +1698,13 @@
>           CMSetProperty(inst, "Name",
>                         (CMPIValue *)"MigrationService", CMPI_chars);
>
> -        CMSetProperty(inst, "SystemName",
> -                      (CMPIValue *)name, CMPI_chars);
> +        if (name != NULL)
> +                CMSetProperty(inst, "SystemName",
> +                              (CMPIValue *)name, CMPI_chars);
>
> -        CMSetProperty(inst, "SystemCreationClassName",
> -                      (CMPIValue *)ccname, CMPI_chars);
> +        if (ccname != NULL)
> +                CMSetProperty(inst, "SystemCreationClassName",
> +                              (CMPIValue *)ccname, CMPI_chars);
>
>           if (is_get_inst) {
>                   s = cu_validate_ref(broker, ref, inst);
> diff -r 62c565a5f714 -r 6e35991ef06d src/Virt_VirtualSystemManagementService.c
> --- a/src/Virt_VirtualSystemManagementService.c	Mon Mar 21 21:35:54 2011 -0400
> +++ b/src/Virt_VirtualSystemManagementService.c	Wed Mar 23 09:32:46 2011 -0700
> @@ -3057,11 +3057,13 @@
>           CMSetProperty(inst, "Name",
>                         (CMPIValue *)"Management Service", CMPI_chars);
>
> -        CMSetProperty(inst, "SystemName",
> -                      (CMPIValue *)name, CMPI_chars);
> -
> -        CMSetProperty(inst, "SystemCreationClassName",
> -                      (CMPIValue *)ccname, CMPI_chars);
> +        if (name != NULL)
> +                CMSetProperty(inst, "SystemName",
> +                              (CMPIValue *)name, CMPI_chars);
> +
> +        if (ccname != NULL)
> +                CMSetProperty(inst, "SystemCreationClassName",
> +                              (CMPIValue *)ccname, CMPI_chars);
>
>           CMSetProperty(inst, "Changeset",
>                         (CMPIValue *)LIBVIRT_CIM_CS, CMPI_chars);
> diff -r 62c565a5f714 -r 6e35991ef06d src/Virt_VirtualSystemSnapshotService.c
> --- a/src/Virt_VirtualSystemSnapshotService.c	Mon Mar 21 21:35:54 2011 -0400
> +++ b/src/Virt_VirtualSystemSnapshotService.c	Wed Mar 23 09:32:46 2011 -0700
> @@ -626,8 +626,8 @@
>                                         CMPIInstance *inst)
>   {
>           CMPIStatus s = {CMPI_RC_OK, NULL};
> -        const char *name;
> -        const char *ccname;
> +        const char *name = NULL;
> +        const char *ccname = NULL;
>
>           s = get_host_system_properties(&name,
>                                          &ccname,
> @@ -644,11 +644,13 @@
>           CMSetProperty(inst, "Name",
>                         (CMPIValue *)"SnapshotService", CMPI_chars);
>
> -        CMSetProperty(inst, "SystemName",
> -                      (CMPIValue *)name, CMPI_chars);
> +        if (name != NULL)
> +                CMSetProperty(inst, "SystemName",
> +                              (CMPIValue *)name, CMPI_chars);
>
> -        CMSetProperty(inst, "SystemCreationClassName",
> -                      (CMPIValue *)ccname, CMPI_chars);
> +        if (ccname != NULL)
> +                CMSetProperty(inst, "SystemCreationClassName",
> +                              (CMPIValue *)ccname, CMPI_chars);
>
>    out:
>           return s;
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim

-- 
Chip Vincent
Open Virtualization
IBM Linux Technology Center
cvincent at linux.vnet.ibm.com




More information about the Libvirt-cim mailing list