diff mbox series

[4/4] e2fsck: initialize variable before first use in fast commit replay

Message ID 20210219210333.1439525-4-harshads@google.com
State Superseded
Headers show
Series [1/4] e2fsck: don't ignore return values in e2fsck_rewrite_extent_tree | expand

Commit Message

Harshad Shirwadkar Feb. 19, 2021, 9:03 p.m. UTC
From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>

Initialize ext2fs_ex variable in ext4_fc_replay_scan() before first
use.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
---
 e2fsck/journal.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Theodore Ts'o Feb. 21, 2021, 11:14 p.m. UTC | #1
On Fri, Feb 19, 2021 at 01:03:33PM -0800, Harshad Shirwadkar wrote:
> From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
> 
> Initialize ext2fs_ex variable in ext4_fc_replay_scan() before first
> use.
> 
> Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>

I wonder if we should make the following change to
ext2fs_decode_extent(), which will prevent other future bugs to
potential users of the function:

	to->e_pblk = ext2fs_le32_to_cpu(from->ee_start) +
		((__u64) ext2fs_le16_to_cpu(from->ee_start_hi)
			<< 32);
	to->e_lblk = ext2fs_le32_to_cpu(from->ee_block);
	to->e_len = ext2fs_le16_to_cpu(from->ee_len);
-	to->e_flags |= EXT2_EXTENT_FLAGS_LEAF;
+	to->e_flags = EXT2_EXTENT_FLAGS_LEAF;

ext2fs_decode_extent() overwrites all other members of the structure,
so we might as well just initialize e_flags as opposed to depending
the caller to initiaize *to just for the sake of to->e_flags.

Cheers,

					- Ted
Harshad Shirwadkar Feb. 23, 2021, 5:41 p.m. UTC | #2
Thanks Ted, it makes sense, will fix this in V2.

- Harshad

On Sun, Feb 21, 2021 at 3:14 PM Theodore Ts'o <tytso@mit.edu> wrote:
>
> On Fri, Feb 19, 2021 at 01:03:33PM -0800, Harshad Shirwadkar wrote:
> > From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
> >
> > Initialize ext2fs_ex variable in ext4_fc_replay_scan() before first
> > use.
> >
> > Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
>
> I wonder if we should make the following change to
> ext2fs_decode_extent(), which will prevent other future bugs to
> potential users of the function:
>
>         to->e_pblk = ext2fs_le32_to_cpu(from->ee_start) +
>                 ((__u64) ext2fs_le16_to_cpu(from->ee_start_hi)
>                         << 32);
>         to->e_lblk = ext2fs_le32_to_cpu(from->ee_block);
>         to->e_len = ext2fs_le16_to_cpu(from->ee_len);
> -       to->e_flags |= EXT2_EXTENT_FLAGS_LEAF;
> +       to->e_flags = EXT2_EXTENT_FLAGS_LEAF;
>
> ext2fs_decode_extent() overwrites all other members of the structure,
> so we might as well just initialize e_flags as opposed to depending
> the caller to initiaize *to just for the sake of to->e_flags.
>
> Cheers,
>
>                                         - Ted
diff mbox series

Patch

diff --git a/e2fsck/journal.c b/e2fsck/journal.c
index a67ef745..8e7ba819 100644
--- a/e2fsck/journal.c
+++ b/e2fsck/journal.c
@@ -289,7 +289,7 @@  static int ext4_fc_replay_scan(journal_t *j, struct buffer_head *bh,
 	struct ext4_fc_tail *tail;
 	__u8 *start, *end;
 	struct ext4_fc_head *head;
-	struct ext2fs_extent ext2fs_ex;
+	struct ext2fs_extent ext2fs_ex = {0};
 
 	state = &ctx->fc_replay_state;