[15/25] filefrag: Fix uninitialized "expected" value

Submitted by Eric Sandeen on Sept. 16, 2011, 8:49 p.m.

Details

Message ID 1316206180-6375-16-git-send-email-sandeen@redhat.com
State Accepted, archived
Headers show

Commit Message

Eric Sandeen Sept. 16, 2011, 8:49 p.m.
The "count" variable is only ever set if FIBMAP is used,
due to the -B switch, or a fiemap failure.  However,
we use it unconditionally to calculate "expected" for
extN files, so we can end up printing garbage.

Initialize count to 0, and unless we go through the FIBMAP
path, expected will be 0 as well, and in that case do not
print the message.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
 misc/filefrag.c |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)

Comments

Theodore Ts'o Sept. 16, 2011, 10:56 p.m.
On Fri, Sep 16, 2011 at 03:49:30PM -0500, Eric Sandeen wrote:
> The "count" variable is only ever set if FIBMAP is used,
> due to the -B switch, or a fiemap failure.  However,
> we use it unconditionally to calculate "expected" for
> extN files, so we can end up printing garbage.
> 
> Initialize count to 0, and unless we go through the FIBMAP
> path, expected will be 0 as well, and in that case do not
> print the message.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Applied, thanks.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch hide | download patch | download mbox

diff --git a/misc/filefrag.c b/misc/filefrag.c
index 2795e15..b055c2b 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -272,7 +272,7 @@  static void frag_report(const char *filename)
 #endif
 	int		bs;
 	long		fd;
-	unsigned long	block, last_block = 0, numblocks, i, count;
+	unsigned long	block, last_block = 0, numblocks, i, count = 0;
 	long		bpib;	/* Blocks per indirect block */
 	long		cylgroups;
 	int		num_extents = 0, expected;
@@ -373,8 +373,9 @@  static void frag_report(const char *filename)
 		printf("%s: 1 extent found", filename);
 	else
 		printf("%s: %d extents found", filename, num_extents);
+	/* count, and thus expected, only set for indirect FIBMAP'd files */
 	expected = (count/((bs*8)-(fsinfo.f_files/8/cylgroups)-3))+1;
-	if (is_ext2 && expected < num_extents)
+	if (is_ext2 && expected && expected < num_extents)
 		printf(", perfection would be %d extent%s\n", expected,
 			(expected>1) ? "s" : "");
 	else