Skip to content

Commit 1d5ded2

Browse files
ryaotonyhutter
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 6ccfa59 commit 1d5ded2

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
@@ -8535,7 +8535,7 @@ static int
85358535
zfs_do_wait(int argc, char **argv)
85368536
{
85378537
boolean_t enabled[ZFS_WAIT_NUM_ACTIVITIES];
8538-
int error, i;
8538+
int error = 0, i;
85398539
int c;
85408540

85418541
/* 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
@@ -467,19 +467,18 @@ get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
467467
uint64_t guid;
468468
uint_t children = 0;
469469
nvlist_t **child = NULL;
470-
uint_t holes;
471470
uint64_t *hole_array, max_id;
472471
uint_t c;
473472
boolean_t isactive;
474-
uint64_t hostid;
475473
nvlist_t *nvl;
476474
boolean_t valid_top_config = B_FALSE;
477475

478476
if (nvlist_alloc(&ret, 0, 0) != 0)
479477
goto nomem;
480478

481479
for (pe = pl->pools; pe != NULL; pe = pe->pe_next) {
482-
uint64_t id, max_txg = 0;
480+
uint64_t id, max_txg = 0, hostid = 0;
481+
uint_t holes = 0;
483482

484483
if (nvlist_alloc(&config, NV_UNIQUE_NAME, 0) != 0)
485484
goto nomem;

0 commit comments

Comments
 (0)