aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2024-04-23 21:37:03 -0400
committerTheodore Ts'o <tytso@mit.edu>2024-04-23 21:37:03 -0400
commita12302fa683e397a731e679bd1b818c45ad3ff78 (patch)
tree406b118b1679cf5f386dc3f4a05466de2320ea6b
parent49125d40ff36490af218f46b9b4d1fdf96553dcd (diff)
downloade2fsprogs-a12302fa683e397a731e679bd1b818c45ad3ff78.tar.gz
e2fsck: make sure get_backup_sb() works when ctx is NULL
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: b53ce7848c2e ("e2fsck: don't try backup superblocks beyond...") Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--e2fsck/util.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/e2fsck/util.c b/e2fsck/util.c
index 734e45cad..b8deb412f 100644
--- a/e2fsck/util.c
+++ b/e2fsck/util.c
@@ -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,