Message ID | 507D4D4F.10807@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
diff --git a/mkfs.c b/mkfs.c index 2cc6051..11e64d2 100644 --- a/mkfs.c +++ b/mkfs.c @@ -60,6 +60,7 @@ static u64 parse_size(char *s) char c; u64 mult = 1; u64 ret; + int i; s = strdup(s); @@ -80,6 +81,16 @@ static u64 parse_size(char *s) } s[len - 1] = '\0'; } + + len = strlen(s); + for (i = 0; i < len; i++) { + if (!isdigit(s[i])) { + fprintf(stderr, "Illegal size value contains " + "non-digit character %c\n", s[i]); + exit(1); + } + } + ret = atol(s) * mult; free(s); return ret;
When we run mkfs.btrfs, we can specify the size value for leafsize, etc. Current the limit is 65536, and the lower limit is 4096. Also, the size should be 4096 aligned. When we specify such value, parse_size just check the tailing non-digit character, but doesn't check other characters. For example, run "mkfs.btrfs -l 40960b btrfs.img" will get nodesize 40960, leafsize 40960 and sectorsize 4096, which is expected. But if we typo 4096bb, "mkfs.btrfs -l 4096bb btrfs.img", the result is nodesize 4096, leafsize 4096 and sectorsize 4096, which maybe not what we want and what we really want to type is 40960b. Add check in parse_size to deal with the non-tailing non-digit characters. Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com> --- mkfs.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)