[libvirt PATCH 1/3] bhyve: fix NULL pointer check position

Ján Tomko posted 3 patches 5 years, 6 months ago
There is a newer version of this series
[libvirt PATCH 1/3] bhyve: fix NULL pointer check position
Posted by Ján Tomko 5 years, 6 months ago
src/bhyve/bhyve_parse_command.c:437:9: warning: Either the condition
'!config' is redundant or there is possible null pointer dereference:
config. [nullPointerRedundantCheck]

src/bhyve/bhyve_parse_command.c:280:23: warning: Either the condition
'!separator' is redundant or there is pointer arithmetic
with NULL pointer. [nullPointerArithmeticRedundantCheck]

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 src/bhyve/bhyve_parse_command.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
index b2d2280872..5e9cf7ba13 100644
--- a/src/bhyve/bhyve_parse_command.c
+++ b/src/bhyve/bhyve_parse_command.c
@@ -277,11 +277,11 @@ bhyveParseBhyveLPCArg(virDomainDefPtr def,
     char *type = NULL;
 
     separator = strchr(arg, ',');
+
+    if (!separator)
+        goto error;
+
     param = separator + 1;
-
-    if (!separator)
-        goto error;
-
     type = g_strndup(arg, separator - arg);
 
     /* Only support com%d */
@@ -434,14 +434,14 @@ bhyveParsePCIDisk(virDomainDefPtr def,
     disk->info.addr.pci.slot = pcislot;
     disk->info.addr.pci.function = function;
 
+    if (!config)
+        goto error;
+
     if (STRPREFIX(config, "/dev/"))
         disk->src->type = VIR_STORAGE_TYPE_BLOCK;
     else
         disk->src->type = VIR_STORAGE_TYPE_FILE;
 
-    if (!config)
-        goto error;
-
     separator = strchr(config, ',');
     if (separator)
         disk->src->path = g_strndup(config, separator - config);
-- 
2.26.2

Re: [libvirt PATCH 1/3] bhyve: fix NULL pointer check position
Posted by Roman Bogorodskiy 5 years, 6 months ago
  Ján Tomko wrote:

> src/bhyve/bhyve_parse_command.c:437:9: warning: Either the condition
> '!config' is redundant or there is possible null pointer dereference:
> config. [nullPointerRedundantCheck]
> 
> src/bhyve/bhyve_parse_command.c:280:23: warning: Either the condition
> '!separator' is redundant or there is pointer arithmetic
> with NULL pointer. [nullPointerArithmeticRedundantCheck]
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>  src/bhyve/bhyve_parse_command.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/src/bhyve/bhyve_parse_command.c b/src/bhyve/bhyve_parse_command.c
> index b2d2280872..5e9cf7ba13 100644
> --- a/src/bhyve/bhyve_parse_command.c
> +++ b/src/bhyve/bhyve_parse_command.c
> @@ -277,11 +277,11 @@ bhyveParseBhyveLPCArg(virDomainDefPtr def,
>      char *type = NULL;
>  
>      separator = strchr(arg, ',');
> +
> +    if (!separator)
> +        goto error;
> +
>      param = separator + 1;
> -
> -    if (!separator)
> -        goto error;
> -
>      type = g_strndup(arg, separator - arg);
>  
>      /* Only support com%d */
> @@ -434,14 +434,14 @@ bhyveParsePCIDisk(virDomainDefPtr def,
>      disk->info.addr.pci.slot = pcislot;
>      disk->info.addr.pci.function = function;
>  
> +    if (!config)
> +        goto error;
> +
>      if (STRPREFIX(config, "/dev/"))
>          disk->src->type = VIR_STORAGE_TYPE_BLOCK;
>      else
>          disk->src->type = VIR_STORAGE_TYPE_FILE;
>  
> -    if (!config)
> -        goto error;
> -
>      separator = strchr(config, ',');
>      if (separator)
>          disk->src->path = g_strndup(config, separator - config);

Reviewed-by: Roman Bogorodskiy <bogorodskiy@gmail.com>

> -- 
> 2.26.2
> 


Roman Bogorodskiy