Skip to contentSkip to conversation

Btrfs-progs: fix parse_limit function to return errors when parsing unit

PATCH In review Wang Shilong 3 participants 4 messages Feb 21, 2013 – Feb 28, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs-progs: fix parse_limit function to return errors when parsing unit

From: Wang Shilong <[email protected]>

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.

---
 cmds-qgroup.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
cmds-qgroup.c +8 -1
index 1525c11..c75ef9b 100644
@@ -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;
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 8 lines · Wang Shilong

From: Wang Shilong <[email protected]>

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.

I don't think we should allow to accept bare units for specifing numbers, so in that case fail with 'unrecognized limit'.

david

#2 lore raw
Quoted 6 lines · David Sterba
Quoted 5 lines · Wang Shilong

From: Wang Shilong <[email protected]>

Steps to reproduce:
btrfs qgroup limit m <mnt>/subv

Quoted 6 lines
Quoted 3 lines

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.

I don't think we should allow to accept bare units for specifing numbers, so in that case fail with 'unrecognized limit'.

I agree with that.

Maybe since David didn't quite want to take my patch 01/17, and Zach thought we needed better code for it all, and Goffredo didn't like the exit() from parse_size, and now this problem, we need a single, concerted effort to fix up size parsing.

Who knew it was so hard? :)

-Eric

Quoted 6 lines

david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw

Hello, Eric, David

2013/2/27 Eric Sandeen <[email protected]>:

Quoted 14 lines · David Sterba
Quoted 6 lines · Wang Shilong
Quoted 5 lines

From: Wang Shilong <[email protected]>

Steps to reproduce:
btrfs qgroup limit m <mnt>/subv

Quoted 6 lines
Quoted 3 lines

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.

I don't think we should allow to accept bare units for specifing numbers, so in that case fail with 'unrecognized limit'.

Quoted 6 lines

I agree with that.

Maybe since David didn't quite want to take my patch 01/17, and Zach thought we needed better code for it all, and Goffredo didn't like the exit() from parse_size, and now this problem, we need a single, concerted effort to fix up size parsing.

I Agre exit() should not be used in parse_size... But i don't agree with Zach about better code for it...

Maybe like this:

int parse_size(const char *s, u64 * size)..

Many places that use the function parse_size/parse_limit, they have to be corrected after change....

Thanks,
Wang

Quoted 12 lines

Who knew it was so hard? :)

-Eric

Quoted 6 lines

david
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html