Skip to content

Commit 31dac16

Browse files
ryaodatacore-rm
authored andcommitted
Fix theoretical use of uninitialized values
Clang's static analyzer complains about this. In get_configs(), if we have an invalid configuration that has no top level vdevs, we can read a couple of uninitialized variables. Aborting upon seeing this would break the userland tools for healthy pools, so we instead initialize the two variables to 0 to allow the userland tools to continue functioning for the pools with valid configurations. In zfs_do_wait(), if no wait activities are enabled, we read an uninitialized error variable. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Richard Yao <[email protected]> Closes openzfs#14043
1 parent 06a1f6c commit 31dac16

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

cmd/zfs/zfs_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8527,7 +8527,7 @@ static int
85278527
zfs_do_wait(int argc, char **argv)
85288528
{
85298529
boolean_t enabled[ZFS_WAIT_NUM_ACTIVITIES];
8530-
int error, i;
8530+
int error = 0, i;
85318531
int c;
85328532

85338533
/* By default, wait for all types of activity. */

lib/libzutil/zutil_import.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,19 +480,18 @@ get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
480480
uint64_t guid;
481481
uint_t children = 0;
482482
nvlist_t **child = NULL;
483-
uint_t holes;
484483
uint64_t *hole_array, max_id;
485484
uint_t c;
486485
boolean_t isactive;
487-
uint64_t hostid;
488486
nvlist_t *nvl;
489487
boolean_t valid_top_config = B_FALSE;
490488

491489
if (nvlist_alloc(&ret, 0, 0) != 0)
492490
goto nomem;
493491

494492
for (pe = pl->pools; pe != NULL; pe = pe->pe_next) {
495-
uint64_t id, max_txg = 0;
493+
uint64_t id, max_txg = 0, hostid = 0;
494+
uint_t holes = 0;
496495

497496
if (nvlist_alloc(&config, NV_UNIQUE_NAME, 0) != 0)
498497
goto nomem;

0 commit comments

Comments
 (0)