All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] use proper pv structure in process_each_segment_in_pv
@ 2009-04-06  8:31 Milan Broz
  2009-04-06 14:55 ` Petr Rockai
  0 siblings, 1 reply; 2+ messages in thread
From: Milan Broz @ 2009-04-06  8:31 UTC (permalink / raw)
  To: lvm-devel

Use pv from newly read vg to avoid possible unallocated memory use.

If the vg in process_each_segment_in_pv is NULL, the pv struct
can be incomplete (for example lv_segs are not copied in get_pvs()
call).

We need use the new pv from just read-in volume group.

(The same code is in pvdisplay already.)

Signed-off-by: Milan Broz <mbroz@redhat.com>
---
 tools/toollib.c |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/tools/toollib.c b/tools/toollib.c
index 1a2fd01..aa2194c 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -364,6 +364,7 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
 						      void *handle))
 {
 	struct pv_segment *pvseg;
+	struct pv_list *pvl;
 	const char *vg_name = NULL;
 	int ret_max = ECMD_PROCESSED;
 	int ret;
@@ -376,6 +377,18 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
 			log_error("Skipping volume group %s", vg_name);
 			return ECMD_FAILED;
 		}
+
+		/*
+		 * Replace possibly incomplete PV structure with new one
+		 * allocated in vg_read_internal() path.
+		 */
+		if (!(pvl = find_pv_in_vg(vg, pv_dev_name(pv)))) {
+			 log_error("Unable to find %s in volume group %s",
+				   pv_dev_name(pv), vg_name);
+			return ECMD_FAILED;
+		}
+
+		pv = pvl->pv;
 	}
 
 	dm_list_iterate_items(pvseg, &pv->segments) {




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

* [PATCH] use proper pv structure in process_each_segment_in_pv
  2009-04-06  8:31 [PATCH] use proper pv structure in process_each_segment_in_pv Milan Broz
@ 2009-04-06 14:55 ` Petr Rockai
  0 siblings, 0 replies; 2+ messages in thread
From: Petr Rockai @ 2009-04-06 14:55 UTC (permalink / raw)
  To: lvm-devel

Milan Broz <mbroz@redhat.com> writes:
> Use pv from newly read vg to avoid possible unallocated memory use.
Do you maybe mean uninitialised here?

> We need use the new pv from just read-in volume group.
Quite sensible.

> Signed-off-by: Milan Broz <mbroz@redhat.com>
Acked-By: Petr Ro?kai <prockai@redhat.com>

> diff --git a/tools/toollib.c b/tools/toollib.c
> index 1a2fd01..aa2194c 100644
> --- a/tools/toollib.c
> +++ b/tools/toollib.c
> @@ -364,6 +364,7 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
>  						      void *handle))
>  {
>  	struct pv_segment *pvseg;
> +	struct pv_list *pvl;
>  	const char *vg_name = NULL;
>  	int ret_max = ECMD_PROCESSED;
>  	int ret;
> @@ -376,6 +377,18 @@ int process_each_segment_in_pv(struct cmd_context *cmd,
>  			log_error("Skipping volume group %s", vg_name);
>  			return ECMD_FAILED;
>  		}
> +
> +		/*
> +		 * Replace possibly incomplete PV structure with new one
> +		 * allocated in vg_read_internal() path.
> +		 */
> +		if (!(pvl = find_pv_in_vg(vg, pv_dev_name(pv)))) {
> +			 log_error("Unable to find %s in volume group %s",
> +				   pv_dev_name(pv), vg_name);
> +			return ECMD_FAILED;
> +		}
> +
> +		pv = pvl->pv;
>  	}
>  
>  	dm_list_iterate_items(pvseg, &pv->segments) {
Check.

-- 
Peter Rockai | me()mornfall!net | prockai()redhat!com
 http://blog.mornfall.net | http://web.mornfall.net

"In My Egotistical Opinion, most people's C programs should be
 indented six feet downward and covered with dirt."
     -- Blair P. Houghton on the subject of C program indentation



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

end of thread, other threads:[~2009-04-06 14:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-06  8:31 [PATCH] use proper pv structure in process_each_segment_in_pv Milan Broz
2009-04-06 14:55 ` Petr Rockai

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.