From: Wang Shilong <wangsl-fnst@xxxxxxxxxxxxxx>
Steps to reproduce:
btrfs qgroup limit m <mnt>/subv
Here, unit(k/K/g/G/m/M/t/T) all will trigger the problem.
For the above command, the original code will parse the limit value as 0
and return successfully.It is wrong,fix it.
Signed-off-by: Wang Shilong <wangsl-fnst@xxxxxxxxxxxxxx>
---
cmds-qgroup.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 1525c11..c75ef9b 100644
--- a/cmds-qgroup.c
+++ b/cmds-qgroup.c
@@ -214,6 +214,8 @@ static int parse_limit(const char *p, unsigned long long *s)
{
char *endptr;
unsigned long long size;
+ int len = strlen(p);
+ int unit = 0;
if (strcasecmp(p, "none") == 0) {
*s = 0;
@@ -232,6 +234,7 @@ static int parse_limit(const char *p, unsigned long long *s)
size *= 1024;
case 'K':
case 'k':
+ unit = 1;
size *= 1024;
++endptr;
break;
@@ -241,7 +244,11 @@ static int parse_limit(const char *p, unsigned long long *s)
return 0;
}
- if (*endptr)
+ /*
+ * (len==1 && unit) means
+ * limit passed is like k,K,m,M,g,G,t,T.
+ */
+ if (*endptr || (len == 1 && unit))
return 0;
*s = size;
--
1.7.7.6
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html