Skip to content

Commit a117a6d

Browse files
grwilsonbehlendorf
authored andcommitted
Illumos #3522
3522 zfs module should not allow uninitialized variables Reviewed by: Sebastien Roy <seb@delphix.com> Reviewed by: Adam Leventhal <ahl@delphix.com> Reviewed by: Matthew Ahrens <mahrens@delphix.com> Approved by: Garrett D'Amore <garrett@damore.org> References: https://www.illumos.org/issues/3522 illumos/illumos-gate@d5285ca Ported-by: Richard Yao <ryao@gentoo.org> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Porting notes: 1. ZFSOnLinux had already addressed many of these issues because of its use of -Wall. However, the manner in which they were addressed differed. The illumos fixes replace the ones previously made in ZFSOnLinux to reduce code differences. 2. Part of the upstream patch made a small change to arc.c that might address #1334. 3. The initialization of aclsize in zfs_log_create() differs because vsecp is a NULL pointer on ZFSOnLinux. 4. The changes to zfs_register_callbacks() were dropped because it has diverged and needs to be resynced.
1 parent a35beed commit a117a6d

File tree

12 files changed

+31
-22
lines changed

12 files changed

+31
-22
lines changed

module/zfs/arc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3089,7 +3089,7 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, arc_done_func_t *done,
30893089
uint64_t size = BP_GET_LSIZE(bp);
30903090
arc_callback_t *acb;
30913091
vdev_t *vd = NULL;
3092-
uint64_t addr = -1;
3092+
uint64_t addr = 0;
30933093
boolean_t devw = B_FALSE;
30943094

30953095
if (hdr == NULL) {
@@ -3210,6 +3210,10 @@ arc_read(zio_t *pio, spa_t *spa, const blkptr_t *bp, arc_done_func_t *done,
32103210
cb->l2rcb_flags = zio_flags;
32113211
cb->l2rcb_compress = hdr->b_l2hdr->b_compress;
32123212

3213+
ASSERT(addr >= VDEV_LABEL_START_SIZE &&
3214+
addr + size < vd->vdev_psize -
3215+
VDEV_LABEL_END_SIZE);
3216+
32133217
/*
32143218
* l2arc read. The SCL_L2ARC lock will be
32153219
* released by l2arc_read_done().
@@ -3480,8 +3484,8 @@ arc_release(arc_buf_t *buf, void *tag)
34803484
if (l2hdr) {
34813485
mutex_enter(&l2arc_buflist_mtx);
34823486
hdr->b_l2hdr = NULL;
3483-
buf_size = hdr->b_size;
34843487
}
3488+
buf_size = hdr->b_size;
34853489

34863490
/*
34873491
* Do we have more than one buf?

module/zfs/dmu.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,7 @@ dmu_buf_hold_array_by_dnode(dnode_t *dn, uint64_t offset, uint64_t length,
400400

401401
if (dn->dn_objset->os_dsl_dataset)
402402
dp = dn->dn_objset->os_dsl_dataset->ds_dir->dd_pool;
403-
if (dp && dsl_pool_sync_context(dp))
404-
start = gethrtime();
403+
start = gethrtime();
405404
zio = zio_root(dn->dn_objset->os_spa, NULL, NULL, ZIO_FLAG_CANFAIL);
406405
blkid = dbuf_whichblock(dn, offset);
407406
for (i = 0; i < nblks; i++) {

module/zfs/dmu_objset.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,8 @@ dmu_objset_userquota_get_ids(dnode_t *dn, boolean_t before, dmu_tx_t *tx)
11981198
objset_t *os = dn->dn_objset;
11991199
void *data = NULL;
12001200
dmu_buf_impl_t *db = NULL;
1201-
uint64_t *user = NULL, *group = NULL;
1201+
uint64_t *user = NULL;
1202+
uint64_t *group = NULL;
12021203
int flags = dn->dn_id_flags;
12031204
int error;
12041205
boolean_t have_spill = B_FALSE;

module/zfs/dsl_dataset.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,8 @@ dsl_dataset_hold_obj(dsl_pool_t *dp, uint64_t dsobj, void *tag,
431431
ds->ds_reserved = ds->ds_quota = 0;
432432
}
433433

434-
if (err == 0) {
435-
winner = dmu_buf_set_user_ie(dbuf, ds, &ds->ds_phys,
436-
dsl_dataset_evict);
437-
}
438-
if (err || winner) {
434+
if (err != 0 || (winner = dmu_buf_set_user_ie(dbuf, ds,
435+
&ds->ds_phys, dsl_dataset_evict)) != NULL) {
439436
bplist_destroy(&ds->ds_pending_deadlist);
440437
dsl_deadlist_close(&ds->ds_deadlist);
441438
if (ds->ds_prev)

module/zfs/dsl_scan.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,8 @@ dsl_scan_scrub_cb(dsl_pool_t *dp,
16441644
zio_priority = ZIO_PRIORITY_SCRUB;
16451645
needs_io = B_TRUE;
16461646
scan_delay = zfs_scrub_delay;
1647-
} else if (scn->scn_phys.scn_func == POOL_SCAN_RESILVER) {
1647+
} else {
1648+
ASSERT3U(scn->scn_phys.scn_func, ==, POOL_SCAN_RESILVER);
16481649
zio_flags |= ZIO_FLAG_RESILVER;
16491650
zio_priority = ZIO_PRIORITY_RESILVER;
16501651
needs_io = B_FALSE;

module/zfs/lzjb.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ lzjb_compress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
5050
{
5151
uchar_t *src = s_start;
5252
uchar_t *dst = d_start;
53-
uchar_t *cpy, *copymap = NULL;
53+
uchar_t *cpy;
54+
uchar_t *copymap = NULL;
5455
int copymask = 1 << (NBBY - 1);
5556
int mlen, offset, hash;
5657
uint16_t *hp;
@@ -104,7 +105,8 @@ lzjb_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
104105
uchar_t *src = s_start;
105106
uchar_t *dst = d_start;
106107
uchar_t *d_end = (uchar_t *)d_start + d_len;
107-
uchar_t *cpy, copymap = 0;
108+
uchar_t *cpy;
109+
uchar_t copymap = 0;
108110
int copymask = 1 << (NBBY - 1);
109111

110112
while (dst < d_end) {

module/zfs/sa.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,8 @@ sa_build_layouts(sa_handle_t *hdl, sa_bulk_attr_t *attr_desc, int attr_count,
679679
int buf_space;
680680
sa_attr_type_t *attrs, *attrs_start;
681681
int i, lot_count;
682-
int hdrsize, spillhdrsize = 0;
682+
int hdrsize;
683+
int spillhdrsize = 0;
683684
int used;
684685
dmu_object_type_t bonustype;
685686
sa_lot_t *lot;

module/zfs/spa.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ spa_load_l2cache(spa_t *spa)
14431443
uint_t nl2cache;
14441444
int i, j, oldnvdevs;
14451445
uint64_t guid;
1446-
vdev_t *vd, **oldvdevs, **newvdevs = NULL;
1446+
vdev_t *vd, **oldvdevs, **newvdevs;
14471447
spa_aux_vdev_t *sav = &spa->spa_l2cache;
14481448

14491449
ASSERT(spa_config_held(spa, SCL_ALL, RW_WRITER) == SCL_ALL);
@@ -1454,6 +1454,7 @@ spa_load_l2cache(spa_t *spa)
14541454
newvdevs = kmem_alloc(nl2cache * sizeof (void *), KM_PUSHPAGE);
14551455
} else {
14561456
nl2cache = 0;
1457+
newvdevs = NULL;
14571458
}
14581459

14591460
oldvdevs = sav->sav_vdevs;

module/zfs/vdev_raidz.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,8 @@ vdev_raidz_matrix_reconstruct(raidz_map_t *rm, int n, int nmissing,
11901190
uint64_t ccount;
11911191
uint8_t *dst[VDEV_RAIDZ_MAXPARITY];
11921192
uint64_t dcount[VDEV_RAIDZ_MAXPARITY];
1193-
uint8_t log = 0, val;
1193+
uint8_t log = 0;
1194+
uint8_t val;
11941195
int ll;
11951196
uint8_t *invlog[VDEV_RAIDZ_MAXPARITY];
11961197
uint8_t *p, *pp;

module/zfs/zfs_fuid.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,9 @@ zfs_fuid_create(zfs_sb_t *zsb, uint64_t id, cred_t *cr,
565565
uint32_t fuid_idx = FUID_INDEX(id);
566566
uint32_t rid;
567567
idmap_stat status;
568-
uint64_t idx;
568+
uint64_t idx = 0;
569569
zfs_fuid_t *zfuid = NULL;
570-
zfs_fuid_info_t *fuidp;
570+
zfs_fuid_info_t *fuidp = NULL;
571571

572572
/*
573573
* If POSIX ID, or entry is already a FUID then
@@ -592,6 +592,9 @@ zfs_fuid_create(zfs_sb_t *zsb, uint64_t id, cred_t *cr,
592592
if (fuidp == NULL)
593593
return (UID_NOBODY);
594594

595+
VERIFY3U(type, >=, ZFS_OWNER);
596+
VERIFY3U(type, <=, ZFS_ACE_GROUP);
597+
595598
switch (type) {
596599
case ZFS_ACE_USER:
597600
case ZFS_ACE_GROUP:
@@ -608,7 +611,7 @@ zfs_fuid_create(zfs_sb_t *zsb, uint64_t id, cred_t *cr,
608611
idx = FUID_INDEX(fuidp->z_fuid_group);
609612
break;
610613
};
611-
domain = fuidp->z_domain_table[idx -1];
614+
domain = fuidp->z_domain_table[idx - 1];
612615
} else {
613616
if (type == ZFS_OWNER || type == ZFS_ACE_USER)
614617
status = kidmap_getsidbyuid(crgetzone(cr), id,

0 commit comments

Comments
 (0)