mkfs.btrfs: write zeroes instead on uninitialized data.
authorSergei Trofimovich <slyfox@gentoo.org>
Sat, 4 Jun 2011 08:19:21 +0000 (11:19 +0300)
committerChris Mason <chris.mason@oracle.com>
Tue, 25 Oct 2011 13:18:58 +0000 (09:18 -0400)
commit8e4b7e883abfca81cd864808da729b2227cff34c
tree3f56df8b1dd5ef4d163edf2c316ceb68cd4f3efc
parentf509f1762e054c3f9bd5e4321dce9240bfd5b03a
mkfs.btrfs: write zeroes instead on uninitialized data.

Found by valgrind:
==8968== Use of uninitialised value of size 8
==8968==    at 0x41CE7D: crc32c_le (crc32c.c:98)
==8968==    by 0x40A1D0: csum_tree_block_size (disk-io.c:82)
==8968==    by 0x40A2D4: csum_tree_block (disk-io.c:105)
==8968==    by 0x40A7D6: write_tree_block (disk-io.c:241)
==8968==    by 0x40ACEE: __commit_transaction (disk-io.c:354)
==8968==    by 0x40AE9E: btrfs_commit_transaction (disk-io.c:385)
==8968==    by 0x42CF66: make_image (mkfs.c:1061)
==8968==    by 0x42DE63: main (mkfs.c:1410)
==8968==  Uninitialised value was created by a stack allocation
==8968==    at 0x42B5FB: add_inode_items (mkfs.c:493)

1. On-disk inode format has reserved (and thus, random at alloc time) fields:
   btrfs_inode_item: __le64 reserved[4]
2. Sometimes extents are created on disk without writing data there.
   (Or at least not all data is written there). Kernel code always had
   it kzalloc'ed.
Zero them all.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
extent_io.c
mkfs.c