Skip to content

Commit a6ccb36

Browse files
authored
Add defensive assertions
Coverity complains about possible bugs involving referencing NULL return values and division by zero. The division by zero bugs require that a block pointer be corrupt, either from in-memory corruption, or on-disk corruption. The NULL return value complaints are only bugs if assumptions that we make about the state of data structures are wrong. Some seem impossible to be wrong and thus are false positives, while others are hard to analyze. Rather than dismiss these as false positives by assuming we know better, we add defensive assertions to let us know when our assumptions are wrong. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Richard Yao <[email protected]> Closes openzfs#13972
1 parent bfaa1d9 commit a6ccb36

File tree

14 files changed

+17
-1
lines changed

14 files changed

+17
-1
lines changed

cmd/zdb/zdb_il.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ zil_prt_rec_write(zilog_t *zilog, int txtype, const void *arg)
182182
return;
183183
}
184184

185+
ASSERT3U(BP_GET_LSIZE(bp), !=, 0);
185186
SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os),
186187
lr->lr_foid, ZB_ZIL_LEVEL,
187188
lr->lr_offset / BP_GET_LSIZE(bp));

module/os/freebsd/zfs/zfs_acl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,7 @@ zfs_acl_data_locator(void **dataptr, uint32_t *length, uint32_t buflen,
11331133
cb->cb_acl_node = list_next(&cb->cb_aclp->z_acl,
11341134
cb->cb_acl_node);
11351135
}
1136+
ASSERT3P(cb->cb_acl_node, !=, NULL);
11361137
*dataptr = cb->cb_acl_node->z_acldata;
11371138
*length = cb->cb_acl_node->z_size;
11381139
}

module/os/linux/zfs/zfs_acl.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ zfs_acl_data_locator(void **dataptr, uint32_t *length, uint32_t buflen,
11631163
cb->cb_acl_node = list_next(&cb->cb_aclp->z_acl,
11641164
cb->cb_acl_node);
11651165
}
1166+
ASSERT3P(cb->cb_acl_node, !=, NULL);
11661167
*dataptr = cb->cb_acl_node->z_acldata;
11671168
*length = cb->cb_acl_node->z_size;
11681169
}

module/zfs/arc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8539,6 +8539,7 @@ l2arc_dev_get_next(void)
85398539
else if (next == first)
85408540
break;
85418541

8542+
ASSERT3P(next, !=, NULL);
85428543
} while (vdev_is_dead(next->l2ad_vdev) || next->l2ad_rebuild ||
85438544
next->l2ad_trim_all);
85448545

module/zfs/dbuf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,6 +2687,7 @@ dbuf_override_impl(dmu_buf_impl_t *db, const blkptr_t *bp, dmu_tx_t *tx)
26872687
dbuf_dirty_record_t *dr;
26882688

26892689
dr = list_head(&db->db_dirty_records);
2690+
ASSERT3P(dr, !=, NULL);
26902691
ASSERT3U(dr->dr_txg, ==, tx->tx_txg);
26912692
dl = &dr->dt.dl;
26922693
dl->dr_overridden_by = *bp;
@@ -2748,6 +2749,7 @@ dmu_buf_write_embedded(dmu_buf_t *dbuf, void *data,
27482749
dmu_buf_will_not_fill(dbuf, tx);
27492750

27502751
dr = list_head(&db->db_dirty_records);
2752+
ASSERT3P(dr, !=, NULL);
27512753
ASSERT3U(dr->dr_txg, ==, tx->tx_txg);
27522754
dl = &dr->dt.dl;
27532755
encode_embedded_bp_compressed(&dl->dr_overridden_by,

module/zfs/dmu_traverse.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ traverse_zil_record(zilog_t *zilog, const lr_t *lrc, void *arg,
111111
if (claim_txg == 0 || bp->blk_birth < claim_txg)
112112
return (0);
113113

114+
ASSERT3U(BP_GET_LSIZE(bp), !=, 0);
114115
SET_BOOKMARK(&zb, td->td_objset, lr->lr_foid,
115116
ZB_ZIL_LEVEL, lr->lr_offset / BP_GET_LSIZE(bp));
116117

module/zfs/dsl_deadlist.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ dsl_deadlist_remove_key(dsl_deadlist_t *dl, uint64_t mintxg, dmu_tx_t *tx)
542542
dle = avl_find(&dl->dl_tree, &dle_tofind, NULL);
543543
ASSERT3P(dle, !=, NULL);
544544
dle_prev = AVL_PREV(&dl->dl_tree, dle);
545+
ASSERT3P(dle_prev, !=, NULL);
545546

546547
dle_enqueue_subobj(dl, dle_prev, dle->dle_bpobj.bpo_object, tx);
547548

module/zfs/dsl_scan.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,6 +1470,7 @@ dsl_scan_zil_record(zilog_t *zilog, const lr_t *lrc, void *arg,
14701470
if (claim_txg == 0 || bp->blk_birth < claim_txg)
14711471
return (0);
14721472

1473+
ASSERT3U(BP_GET_LSIZE(bp), !=, 0);
14731474
SET_BOOKMARK(&zb, zh->zh_log.blk_cksum.zc_word[ZIL_ZC_OBJSET],
14741475
lr->lr_foid, ZB_ZIL_LEVEL,
14751476
lr->lr_offset / BP_GET_LSIZE(bp));

module/zfs/mmp.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,10 @@ mmp_next_leaf(spa_t *spa)
303303

304304
do {
305305
leaf = list_next(&spa->spa_leaf_list, leaf);
306-
if (leaf == NULL)
306+
if (leaf == NULL) {
307307
leaf = list_head(&spa->spa_leaf_list);
308+
ASSERT3P(leaf, !=, NULL);
309+
}
308310

309311
/*
310312
* We skip unwritable, offline, detached, and dRAID spare

module/zfs/range_tree.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ range_tree_add_impl(void *arg, uint64_t start, uint64_t size, uint64_t fill)
369369
* invalid as soon as we do any mutating btree operations.
370370
*/
371371
rs_after = zfs_btree_find(&rt->rt_root, &tmp, &where_after);
372+
ASSERT3P(rs_after, !=, NULL);
372373
rs_set_start_raw(rs_after, rt, before_start);
373374
rs_set_fill(rs_after, rt, after_fill + before_fill + fill);
374375
rs = rs_after;

module/zfs/spa_log_spacemap.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ void
507507
spa_log_summary_decrement_blkcount(spa_t *spa, uint64_t blocks_gone)
508508
{
509509
log_summary_entry_t *e = list_head(&spa->spa_log_summary);
510+
ASSERT3P(e, !=, NULL);
510511
if (e->lse_txgcount > 0)
511512
e->lse_txgcount--;
512513
for (; e != NULL; e = list_head(&spa->spa_log_summary)) {

module/zfs/vdev_indirect.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,7 @@ vdev_indirect_io_start(zio_t *zio)
13191319
vdev_indirect_gather_splits, zio);
13201320

13211321
indirect_split_t *first = list_head(&iv->iv_splits);
1322+
ASSERT3P(first, !=, NULL);
13221323
if (first->is_size == zio->io_size) {
13231324
/*
13241325
* This is not a split block; we are pointing to the entire

module/zfs/vdev_queue.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ vdev_queue_aggregate(vdev_queue_t *vq, zio_t *zio)
756756
do {
757757
dio = nio;
758758
nio = AVL_NEXT(t, dio);
759+
ASSERT3P(dio, !=, NULL);
759760
zio_add_child(dio, aio);
760761
vdev_queue_io_remove(vq, dio);
761762

module/zfs/zil.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,7 @@ zil_read_log_data(zilog_t *zilog, const lr_write_t *lr, void *wbuf)
339339
if (wbuf == NULL)
340340
zio_flags |= ZIO_FLAG_RAW;
341341

342+
ASSERT3U(BP_GET_LSIZE(bp), !=, 0);
342343
SET_BOOKMARK(&zb, dmu_objset_id(zilog->zl_os), lr->lr_foid,
343344
ZB_ZIL_LEVEL, lr->lr_offset / BP_GET_LSIZE(bp));
344345

0 commit comments

Comments
 (0)