diff mbox series

[v3,11/19] libmultipath: fix null dereference int alloc_path_group

Message ID 1537571127-10143-12-git-send-email-bmarzins@redhat.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series Misc Multipath patches | expand

Commit Message

Benjamin Marzinski Sept. 21, 2018, 11:05 p.m. UTC
If all_pathgroup failed to allocate a vector for pgp->paths, instead of
failing after it freed pgp, it would set pgp to NULL and then
dereference it. This patch fixes that. Found by coverity.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 libmultipath/structs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Martin Wilck Oct. 1, 2018, 9:33 p.m. UTC | #1
On Fri, 2018-09-21 at 18:05 -0500, Benjamin Marzinski wrote:
> If all_pathgroup failed to allocate a vector for pgp->paths, instead
> of
> failing after it freed pgp, it would set pgp to NULL and then
> dereference it. This patch fixes that. Found by coverity.
> 
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>

Reviewed-by: Martin Wilck <mwilck@suse.com>

> ---
>  libmultipath/structs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libmultipath/structs.c b/libmultipath/structs.c
> index ae847d6..caa178a 100644
> --- a/libmultipath/structs.c
> +++ b/libmultipath/structs.c
> @@ -165,7 +165,7 @@ alloc_pathgroup (void)
>  
>  	if (!pgp->paths) {
>  		FREE(pgp);
> -		pgp = NULL;
> +		return NULL;
>  	}
>  
>  	dm_pathgroup_to_gen(pgp)->ops = &dm_gen_pathgroup_ops;
diff mbox series

Patch

diff --git a/libmultipath/structs.c b/libmultipath/structs.c
index ae847d6..caa178a 100644
--- a/libmultipath/structs.c
+++ b/libmultipath/structs.c
@@ -165,7 +165,7 @@  alloc_pathgroup (void)
 
 	if (!pgp->paths) {
 		FREE(pgp);
-		pgp = NULL;
+		return NULL;
 	}
 
 	dm_pathgroup_to_gen(pgp)->ops = &dm_gen_pathgroup_ops;