[lvm-devel] [PATCH 3/5] Ensure first is not NULL before dereference

Zdenek Kabelac zkabelac at redhat.com
Tue Oct 26 12:59:24 UTC 2010


clang Logic error Dereference of null pointer

For empty lists make sure the NULL first pointer is not dereferenced
and report error.

Signed-off-by: Zdenek Kabelac <zkabelac at redhat.com>
---
 lib/format1/format1.c |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/lib/format1/format1.c b/lib/format1/format1.c
index 0dcec05..c5685c9 100644
--- a/lib/format1/format1.c
+++ b/lib/format1/format1.c
@@ -102,6 +102,11 @@ static int _check_vgs(struct dm_list *pvs, struct volume_group *vg)
 		pv_count++;
 	}
 
+	if (!first) {
+		log_error(INTERNAL_ERROR "Unexpected empty PV list.");
+		return 0;
+	}
+
 	/* On entry to fn, list known to be non-empty */
 	if (pv_count != first->vgd.pv_cur) {
 		log_error("%d PV(s) found for VG %s: expected %d",
-- 
1.7.3.2




More information about the lvm-devel mailing list