All of lore.kernel.org
 help / color / mirror / Atom feed
From: Milan Broz <mbroz@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH] use proper pv structure in process_each_segment_in_pv
Date: Mon, 06 Apr 2009 10:31:06 +0200	[thread overview]
Message-ID: <49D9BDCA.5060206@redhat.com> (raw)

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) {




             reply	other threads:[~2009-04-06  8:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-06  8:31 Milan Broz [this message]
2009-04-06 14:55 ` [PATCH] use proper pv structure in process_each_segment_in_pv Petr Rockai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=49D9BDCA.5060206@redhat.com \
    --to=mbroz@redhat.com \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.