]> www.infradead.org Git - users/hch/xfsprogs.git/commitdiff
xfs_repair: fix some potential null pointer deferences
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 21 Dec 2016 04:29:01 +0000 (22:29 -0600)
committerEric Sandeen <sandeen@redhat.com>
Wed, 21 Dec 2016 04:29:01 +0000 (22:29 -0600)
Fix some potential NULL pointer deferences that Coverity pointed out,
and remove a trivial dead integer check.

Coverity-id: 1375789137579013757911375792
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
repair/phase5.c
repair/rmap.c
repair/slab.h

index 3604d1d9c8519d110114c95f4e48b5c8da4a0902..cbda556427df70ba79a6dc3165016cda93957207 100644 (file)
@@ -1925,7 +1925,7 @@ _("Insufficient memory to construct refcount cursor."));
        refc_rec = pop_slab_cursor(refc_cur);
        lptr = &btree_curs->level[0];
 
-       for (i = 0; i < lptr->num_blocks; i++)  {
+       for (i = 0; i < lptr->num_blocks && refc_rec != NULL; i++)  {
                /*
                 * block initialization, lay in block header
                 */
index 45e183ac4864c7296f9435c2870079eae98316a4..7508973c581c49729a86a30d5519142fc252daf6 100644 (file)
@@ -790,7 +790,7 @@ compute_refcounts(
                mark_inode_rl(mp, stack_top);
 
                /* Set nbno to the bno of the next refcount change */
-               if (n < slab_count(rmaps))
+               if (n < slab_count(rmaps) && array_cur)
                        nbno = array_cur->rm_startblock;
                else
                        nbno = NULLAGBLOCK;
index 4aa551212581e2902a91451c9f13d10445566d41..a2201f14a981f2413c477f59abe6789f638bef5a 100644 (file)
@@ -54,7 +54,7 @@ extern void *bag_item(struct xfs_bag *, size_t);
 
 #define foreach_bag_ptr_reverse(bag, idx, ptr) \
        for ((idx) = bag_count(bag) - 1, (ptr) = bag_item((bag), (idx)); \
-            (idx) >= 0 && (ptr) != NULL; \
+            (ptr) != NULL; \
             (idx)--, (ptr) = bag_item((bag), (idx)))
 
 #endif /* SLAB_H_ */