[PATCH] lvm: Fix possible NULL value handling

Guillem Jover guillem.jover at nokia.com
Tue Oct 28 16:46:28 UTC 2008


Add a missing NULL check, and correct them by moving the pointer
operations after the actual check.
---
 disk/lvm.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/disk/lvm.c b/disk/lvm.c
index cd9e447..df8c99b 100644
--- a/disk/lvm.c
+++ b/disk/lvm.c
@@ -373,9 +373,10 @@ grub_lvm_scan_device (const char *name)
 	      grub_memcpy (pv->name, p, s);
 	      pv->name[s] = '\0';
 	      
-	      p = grub_strstr (p, "id = \"") + sizeof("id = \"") - 1;
+	      p = grub_strstr (p, "id = \"");
 	      if (p == NULL)
 		goto pvs_fail;
+	      p += sizeof("id = \"") - 1;
 	      
 	      grub_memcpy (pv->id, p, GRUB_LVM_ID_STRLEN);
 	      pv->id[GRUB_LVM_ID_STRLEN] = '\0';
@@ -387,7 +388,10 @@ grub_lvm_scan_device (const char *name)
 	      pv->next = vg->pvs;
 	      vg->pvs = pv;
 	      
-	      p = grub_strchr (p, '}') + 1;
+	      p = grub_strchr (p, '}');
+	      if (p == NULL)
+		goto pvs_fail;
+	      p++;
 	      
 	      continue;
 	    pvs_fail:
-- 
1.6.0.2


--+QahgC5+KEYLbs62
Content-Type: text/x-diff; charset=us-ascii
Content-Disposition: attachment; filename="0002-lvm-Fix-error-recovery-by-only-adding-objects-when.patch"



More information about the Pkg-grub-devel mailing list