Skip to content

Commit

Permalink
Fix theoretical use of uninitialized values
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ryao authored and andrewc12 committed Oct 21, 2022
1 parent f417ab1 commit 0020873
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8554,7 +8554,7 @@ static int
zfs_do_wait(int argc, char **argv)
{
boolean_t enabled[ZFS_WAIT_NUM_ACTIVITIES];
int error, i;
int error = 0, i;
int c;

/* By default, wait for all types of activity. */
Expand Down
5 changes: 2 additions & 3 deletions lib/libzutil/zutil_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -501,19 +501,18 @@ get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
uint64_t guid;
uint_t children = 0;
nvlist_t **child = NULL;
uint_t holes;
uint64_t *hole_array, max_id;
uint_t c;
boolean_t isactive;
uint64_t hostid;
nvlist_t *nvl;
boolean_t valid_top_config = B_FALSE;

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

for (pe = pl->pools; pe != NULL; pe = pe->pe_next) {
uint64_t id, max_txg = 0;
uint64_t id, max_txg = 0, hostid = 0;
uint_t holes = 0;

if (nvlist_alloc(&config, NV_UNIQUE_NAME, 0) != 0)
goto nomem;
Expand Down

0 comments on commit 0020873

Please sign in to comment.