"mke2fs -G" hangs up if an argument value exceeding INT_MAX is specified for the option
Environment
- Red Hat Enterprise Linux 6
- parted-2.1-10.el6.x86_64
- kernel-2.6.32-71.el6.x86_64
- e2fsprogs-1.41.12-3.el6.x86_64
Issue
- "mke2fs -G" hangs up if an argument value exceeding INT_MAX, e.g. 2147483648, is specified for the option.
- The following source code may affect it.
[misc/mke2fs.c] static void PRS(int argc, char *argv[]) { <snip> fs_param.s_log_groups_per_flex = int_log2(flex_bg_size); } - On the above source code, mke2fs calculates logarithm of an argument value specified with -G option by calling the following int_log2().
static int int_log2(int arg) { int l = 0; arg >>= 1; while (arg) { l++; arg >>= 1; } return l; } - As you see, int_log2()'s argument type is "int". If an argument value exceeding INT_MAX, e.g. 2147483648, is specified for -G option, the value of "arg" surely overflows.
Resolution
-
When a value greater than INT_MAX (2147483647) was specified as the argument to mke2fs -G <number of groups>, the command did not complete.
-
This was because the argument for int_log2() was "int", therefore when a value exceeding INT_MAX is specified for the -G option, the value of "arg" overflows.
-
Also, e2fsprogs only supports 2^32 block file systems so asking for anything greater cannot be honored.
-
Therefore, this patch rejects a number that overflows, and restricts it to INT_MAX+1 so the result does not wrap.
- http://rhn.redhat.com/errata/RHBA-2011-0702.html
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
