Skip to content

Commit

Permalink
e2fsck: make sure get_backup_sb() works when ctx is NULL
Browse files Browse the repository at this point in the history
The print_e2fsck_message() function can call get_backup_sb() with the
ctx variable set to NULL.  In that case, we can't dereference
ctx->filesystem_name; instead, we can get the size of the file system
from the ext2fs_block_count(fs->super).

Addresses-Coverity-Bug: 1596517
Addresses-Coverity-Bug: 1596505
Fixes: b53ce78 ("e2fsck: don't try backup superblocks beyond...")
Signed-off-by: Theodore Ts'o <[email protected]>
  • Loading branch information
tytso committed Apr 24, 2024
1 parent 49125d4 commit a12302f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions e2fsck/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,11 @@ blk64_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
blk_t this_bpg = bpg ? bpg : blocksize * 8;
blk64_t num_blocks;

if (ext2fs_get_device_size2(ctx->filesystem_name,
blocksize,
&num_blocks) == 0) {
if (fs && fs->super) {
num_blocks = ext2fs_blocks_count(fs->super);
} else if (ctx && ext2fs_get_device_size2(ctx->filesystem_name,
blocksize,
&num_blocks) == 0) {
limit = num_blocks / this_bpg;
} else {
/* If we can't figure out the device size,
Expand Down

0 comments on commit a12302f

Please sign in to comment.