diff mbox

[01/12] Fix memory issues in path reordering failure code paths

Message ID 1404105243-5071-2-git-send-email-bmarzins@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: christophe varoqui
Headers show

Commit Message

Benjamin Marzinski June 30, 2014, 5:13 a.m. UTC
There were some possible NULL pointer dereferences and multiple frees
in the failure code paths of the path reordering code.  This patch
cleans them up.

Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
---
 libmultipath/configure.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Christophe Varoqui July 1, 2014, 6:45 p.m. UTC | #1
Applied.
Thanks.


On Mon, Jun 30, 2014 at 7:13 AM, Benjamin Marzinski <bmarzins@redhat.com>
wrote:

> There were some possible NULL pointer dereferences and multiple frees
> in the failure code paths of the path reordering code.  This patch
> cleans them up.
>
> Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com>
> ---
>  libmultipath/configure.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/libmultipath/configure.c b/libmultipath/configure.c
> index 3ed6b55..6ad7a80 100644
> --- a/libmultipath/configure.c
> +++ b/libmultipath/configure.c
> @@ -160,8 +160,16 @@ int order_paths_in_pg_by_alt_adapters(struct
> pathgroup *pgp, vector adapters,
>
>         while (total_paths > 0) {
>                 agp = VECTOR_SLOT(adapters, next_adapter_index);
> +               if (!agp) {
> +                       condlog(0, "can't get adapter group %d",
> next_adapter_index);
> +                       return 1;
> +               }
>
>                 hgp = VECTOR_SLOT(agp->host_groups, agp->next_host_index);
> +               if (!hgp) {
> +                       condlog(0, "can't get host group %d of adapter
> group %d", next_adapter_index, agp->next_host_index);
> +                       return 1;
> +               }
>
>                 if (!hgp->num_paths) {
>                         agp->next_host_index++;
> @@ -223,8 +231,8 @@ int rr_optimize_path_order(struct pathgroup *pgp)
>         /* group paths in path group by host adapters
>          */
>         if (group_by_host_adapter(pgp, adapters)) {
> +               /* already freed adapters */
>                 condlog(3, "Failed to group paths by adapters");
> -               free_adaptergroup(adapters);
>                 return 0;
>         }
>
> --
> 1.8.3.1
>
>
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

diff --git a/libmultipath/configure.c b/libmultipath/configure.c
index 3ed6b55..6ad7a80 100644
--- a/libmultipath/configure.c
+++ b/libmultipath/configure.c
@@ -160,8 +160,16 @@  int order_paths_in_pg_by_alt_adapters(struct pathgroup *pgp, vector adapters,
 
 	while (total_paths > 0) {
 		agp = VECTOR_SLOT(adapters, next_adapter_index);
+		if (!agp) {
+			condlog(0, "can't get adapter group %d", next_adapter_index);
+			return 1;
+		}
 
 		hgp = VECTOR_SLOT(agp->host_groups, agp->next_host_index);
+		if (!hgp) {
+			condlog(0, "can't get host group %d of adapter group %d", next_adapter_index, agp->next_host_index);
+			return 1;
+		}
 
 		if (!hgp->num_paths) {
 			agp->next_host_index++;
@@ -223,8 +231,8 @@  int rr_optimize_path_order(struct pathgroup *pgp)
 	/* group paths in path group by host adapters
 	 */
 	if (group_by_host_adapter(pgp, adapters)) {
+		/* already freed adapters */
 		condlog(3, "Failed to group paths by adapters");
-		free_adaptergroup(adapters);
 		return 0;
 	}