Skip to content

Commit d32bef8

Browse files
ryaoandrewc12
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 6621388 commit d32bef8

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
@@ -8554,7 +8554,7 @@ static int
85548554
zfs_do_wait(int argc, char **argv)
85558555
{
85568556
boolean_t enabled[ZFS_WAIT_NUM_ACTIVITIES];
8557-
int error, i;
8557+
int error = 0, i;
85588558
int c;
85598559

85608560
/* 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
@@ -501,19 +501,18 @@ get_configs(libpc_handle_t *hdl, pool_list_t *pl, boolean_t active_ok,
501501
uint64_t guid;
502502
uint_t children = 0;
503503
nvlist_t **child = NULL;
504-
uint_t holes;
505504
uint64_t *hole_array, max_id;
506505
uint_t c;
507506
boolean_t isactive;
508-
uint64_t hostid;
509507
nvlist_t *nvl;
510508
boolean_t valid_top_config = B_FALSE;
511509

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

515513
for (pe = pl->pools; pe != NULL; pe = pe->pe_next) {
516-
uint64_t id, max_txg = 0;
514+
uint64_t id, max_txg = 0, hostid = 0;
515+
uint_t holes = 0;
517516

518517
if (nvlist_alloc(&config, NV_UNIQUE_NAME, 0) != 0)
519518
goto nomem;

0 commit comments

Comments
 (0)