All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] spapr: Fix Coverity warning while validating nvdimm options
@ 2020-02-27 13:42 Shivaprasad G Bhat
  2020-02-27 13:58 ` Greg Kurz
  2020-02-28  1:05 ` David Gibson
  0 siblings, 2 replies; 3+ messages in thread
From: Shivaprasad G Bhat @ 2020-02-27 13:42 UTC (permalink / raw)
  To: qemu-ppc, david; +Cc: peter.maydell, groug, f4bug, qemu-devel

Fixes Coverity issue,
      CID 1419883:  Error handling issues  (CHECKED_RETURN)
           Calling "qemu_uuid_parse" without checking return value

nvdimm_set_uuid() already verifies if the user provided uuid is valid or
not. So, need to check for the validity during pre-plug validation again.

As this a false positive in this case, assert if not valid to be safe.
Also, error_abort if QOM accessor encounters error while fetching the uuid
property.

Reported-by: Coverity (CID 1419883)
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
---
 hw/ppc/spapr_nvdimm.c |    7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c
index 74eeb8bb74..25be8082d7 100644
--- a/hw/ppc/spapr_nvdimm.c
+++ b/hw/ppc/spapr_nvdimm.c
@@ -35,6 +35,7 @@ void spapr_nvdimm_validate_opts(NVDIMMDevice *nvdimm, uint64_t size,
 {
     char *uuidstr = NULL;
     QemuUUID uuid;
+    int ret;
 
     if (size % SPAPR_MINIMUM_SCM_BLOCK_SIZE) {
         error_setg(errp, "NVDIMM memory size excluding the label area"
@@ -43,8 +44,10 @@ void spapr_nvdimm_validate_opts(NVDIMMDevice *nvdimm, uint64_t size,
         return;
     }
 
-    uuidstr = object_property_get_str(OBJECT(nvdimm), NVDIMM_UUID_PROP, NULL);
-    qemu_uuid_parse(uuidstr, &uuid);
+    uuidstr = object_property_get_str(OBJECT(nvdimm), NVDIMM_UUID_PROP,
+                                      &error_abort);
+    ret = qemu_uuid_parse(uuidstr, &uuid);
+    g_assert(!ret);
     g_free(uuidstr);
 
     if (qemu_uuid_is_null(&uuid)) {



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] spapr: Fix Coverity warning while validating nvdimm options
  2020-02-27 13:42 [PATCH v2] spapr: Fix Coverity warning while validating nvdimm options Shivaprasad G Bhat
@ 2020-02-27 13:58 ` Greg Kurz
  2020-02-28  1:05 ` David Gibson
  1 sibling, 0 replies; 3+ messages in thread
From: Greg Kurz @ 2020-02-27 13:58 UTC (permalink / raw)
  To: Shivaprasad G Bhat; +Cc: qemu-devel, peter.maydell, qemu-ppc, f4bug, david

On Thu, 27 Feb 2020 07:42:49 -0600
Shivaprasad G Bhat <sbhat@linux.ibm.com> wrote:

> Fixes Coverity issue,
>       CID 1419883:  Error handling issues  (CHECKED_RETURN)
>            Calling "qemu_uuid_parse" without checking return value
> 
> nvdimm_set_uuid() already verifies if the user provided uuid is valid or
> not. So, need to check for the validity during pre-plug validation again.
> 
> As this a false positive in this case, assert if not valid to be safe.
> Also, error_abort if QOM accessor encounters error while fetching the uuid
> property.
> 
> Reported-by: Coverity (CID 1419883)
> Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
> ---

You should theoretically add the list of changes since the previous
version but fortunately the patch is simple enough to figure this
out :)

LGTM

Reviewed-by: Greg Kurz <groug@kaod.org>

>  hw/ppc/spapr_nvdimm.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c
> index 74eeb8bb74..25be8082d7 100644
> --- a/hw/ppc/spapr_nvdimm.c
> +++ b/hw/ppc/spapr_nvdimm.c
> @@ -35,6 +35,7 @@ void spapr_nvdimm_validate_opts(NVDIMMDevice *nvdimm, uint64_t size,
>  {
>      char *uuidstr = NULL;
>      QemuUUID uuid;
> +    int ret;
>  
>      if (size % SPAPR_MINIMUM_SCM_BLOCK_SIZE) {
>          error_setg(errp, "NVDIMM memory size excluding the label area"
> @@ -43,8 +44,10 @@ void spapr_nvdimm_validate_opts(NVDIMMDevice *nvdimm, uint64_t size,
>          return;
>      }
>  
> -    uuidstr = object_property_get_str(OBJECT(nvdimm), NVDIMM_UUID_PROP, NULL);
> -    qemu_uuid_parse(uuidstr, &uuid);
> +    uuidstr = object_property_get_str(OBJECT(nvdimm), NVDIMM_UUID_PROP,
> +                                      &error_abort);
> +    ret = qemu_uuid_parse(uuidstr, &uuid);
> +    g_assert(!ret);
>      g_free(uuidstr);
>  
>      if (qemu_uuid_is_null(&uuid)) {
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] spapr: Fix Coverity warning while validating nvdimm options
  2020-02-27 13:42 [PATCH v2] spapr: Fix Coverity warning while validating nvdimm options Shivaprasad G Bhat
  2020-02-27 13:58 ` Greg Kurz
@ 2020-02-28  1:05 ` David Gibson
  1 sibling, 0 replies; 3+ messages in thread
From: David Gibson @ 2020-02-28  1:05 UTC (permalink / raw)
  To: Shivaprasad G Bhat; +Cc: peter.maydell, groug, qemu-ppc, f4bug, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 1980 bytes --]

On Thu, Feb 27, 2020 at 07:42:49AM -0600, Shivaprasad G Bhat wrote:
> Fixes Coverity issue,
>       CID 1419883:  Error handling issues  (CHECKED_RETURN)
>            Calling "qemu_uuid_parse" without checking return value
> 
> nvdimm_set_uuid() already verifies if the user provided uuid is valid or
> not. So, need to check for the validity during pre-plug validation again.
> 
> As this a false positive in this case, assert if not valid to be safe.
> Also, error_abort if QOM accessor encounters error while fetching the uuid
> property.
> 
> Reported-by: Coverity (CID 1419883)
> Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>

Applied to ppc-for-5.0, thanks.

> ---
>  hw/ppc/spapr_nvdimm.c |    7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c
> index 74eeb8bb74..25be8082d7 100644
> --- a/hw/ppc/spapr_nvdimm.c
> +++ b/hw/ppc/spapr_nvdimm.c
> @@ -35,6 +35,7 @@ void spapr_nvdimm_validate_opts(NVDIMMDevice *nvdimm, uint64_t size,
>  {
>      char *uuidstr = NULL;
>      QemuUUID uuid;
> +    int ret;
>  
>      if (size % SPAPR_MINIMUM_SCM_BLOCK_SIZE) {
>          error_setg(errp, "NVDIMM memory size excluding the label area"
> @@ -43,8 +44,10 @@ void spapr_nvdimm_validate_opts(NVDIMMDevice *nvdimm, uint64_t size,
>          return;
>      }
>  
> -    uuidstr = object_property_get_str(OBJECT(nvdimm), NVDIMM_UUID_PROP, NULL);
> -    qemu_uuid_parse(uuidstr, &uuid);
> +    uuidstr = object_property_get_str(OBJECT(nvdimm), NVDIMM_UUID_PROP,
> +                                      &error_abort);
> +    ret = qemu_uuid_parse(uuidstr, &uuid);
> +    g_assert(!ret);
>      g_free(uuidstr);
>  
>      if (qemu_uuid_is_null(&uuid)) {
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-02-28  6:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27 13:42 [PATCH v2] spapr: Fix Coverity warning while validating nvdimm options Shivaprasad G Bhat
2020-02-27 13:58 ` Greg Kurz
2020-02-28  1:05 ` David Gibson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.