Check vector_foreach_slot for NULL argument
authorHannes Reinecke <hare@suse.de>
Mon, 24 Nov 2008 07:31:28 +0000 (08:31 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Tue, 21 Apr 2009 22:48:12 +0000 (00:48 +0200)
Most crashes are due to vector_foreach_slot not checking for NULL
argument. Do that now, and add some more checks for not accessing
a NULL pointer indirection.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/configure.c
libmultipath/structs_vec.c
libmultipath/vector.h

index 3646f9a..9f9c118 100644 (file)
@@ -119,6 +119,9 @@ pgcmp (struct multipath * mpp, struct multipath * cmpp)
        struct pathgroup * cpgp;
        int r = 0;
 
+       if (!mpp)
+               return 0;
+
        vector_foreach_slot (mpp->pg, pgp, i) {
                compute_pgid(pgp);
 
index e27827c..c670b3f 100644 (file)
@@ -163,7 +163,7 @@ _remove_maps (struct vectors * vecs, int stop_waiter)
        int i;
        struct multipath * mpp;
 
-       if (!vecs->mpvec)
+       if (!vecs)
                return;
 
        vector_foreach_slot (vecs->mpvec, mpp, i) {
@@ -443,7 +443,7 @@ verify_paths(struct multipath * mpp, struct vectors * vecs, vector rpvec)
        int count = 0;
        int i, j;
 
-       if (!mpp->paths)
+       if (!mpp)
                return 0;
 
        vector_foreach_slot (mpp->paths, pp, i) {
@@ -491,9 +491,6 @@ int update_multipath (struct vectors *vecs, char *mapname)
        if (setup_multipath(vecs, mpp))
                return 1; /* mpp freed in setup_multipath */
 
-       if (!mpp->pg)
-               return 0; /* Can happen when all paths are down */
-
        /*
         * compare checkers states with DM states
         */
index 993ba79..aa9e134 100644 (file)
@@ -36,9 +36,9 @@ typedef struct _vector *vector;
 #define VECTOR_LAST_SLOT(V)   ((V)->slot[((V)->allocated - 1)])
 
 #define vector_foreach_slot(v,p,i) \
-       for (i = 0; i < (v)->allocated && ((p) = (v)->slot[i]); i++)
+       for (i = 0; (v) && i < (v)->allocated && ((p) = (v)->slot[i]); i++)
 #define vector_foreach_slot_after(v,p,i) \
-       for (; i < (v)->allocated && ((p) = (v)->slot[i]); i++)
+       for (; (v) && i < (v)->allocated && ((p) = (v)->slot[i]); i++)
 
 /* Prototypes */
 extern vector vector_alloc(void);