From: Andreas Dilger Date: Thu, 29 Mar 2018 18:36:54 +0000 (-0600) Subject: filefrag: avoid temporary buffer overflow X-Git-Tag: debian/1.44.4-1~9 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=346db5ddf222fef3c9a88676e55f2f38527838e4;p=tools%2Fe2fsprogs.git filefrag: avoid temporary buffer overflow If an unknown flag is present in a FIEMAP extent, it is printed as a hex value into a temporary buffer before adding it to the flags. If that unknown flag is over 0xfff then it will overflow the temporary buffer. Reported-by: Sarah Liu Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-10335 Signed-off-by: Andreas Dilger Signed-off-by: Theodore Ts'o (cherry picked from commit 17a1f2c1929630e3a79e6b98168d56f96acf2e8b) --- diff --git a/misc/filefrag.c b/misc/filefrag.c index 9c57ab9..dc00393 100644 --- a/misc/filefrag.c +++ b/misc/filefrag.c @@ -179,7 +179,7 @@ static void print_extent_info(struct fiemap_extent *fm_extent, int cur_ex, print_flag(&fe_flags, FIEMAP_EXTENT_SHARED, flags, "shared,"); /* print any unknown flags as hex values */ for (mask = 1; fe_flags != 0 && mask != 0; mask <<= 1) { - char hex[6]; + char hex[sizeof(mask) * 2 + 4]; /* 2 chars/byte + 0x, + NUL */ if ((fe_flags & mask) == 0) continue;