Skip to contentSkip to conversation

xfsprogs: check for size parsing errors in xfs_quota

PATCH In review Eric Sandeen 4 participants 7 messages Jan 23, 2012 – Feb 3, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfsprogs: check for size parsing errors in xfs_quota

Doing something like

# xfs_quota -x -c 'limit -u bhard=1.2g ...

will cause cvtnum to fail and return a value of -1LL (because it cannot parse the decimal), but the quota caller doesn't check for this error value, casts it to U64, shifts right, and we end up with an answer of 16 petabytes rather than erroring out. Fix this.

---

quota/edit.c +7 -3
index b704e63..067cd63 100644
@@ -226,13 +226,17 @@ extractb(
 	uint		sectorsize,
 	__uint64_t	*value)
 {
-	__uint64_t	v;
+	long long	v;
 	char		*s = string;
 
 	if (strncmp(string, prefix, length) == 0) {
 		s = string + length + 1;
-		v = (__uint64_t)cvtnum(blocksize, sectorsize, s);
-		*value = v >> 9;	/* syscalls use basic blocks */
+		v = cvtnum(blocksize, sectorsize, s);
+		if (v == -1LL) {
+			fprintf(stderr, _("%s: Error: could not parse size %s.\n"), progname, s);
+			return 0;
+		}
+		*value = (__uint64_t)v >> 8;	/* syscalls use basic blocks */
 		if (v > 0 && *value == 0)
 			fprintf(stderr, _("%s: Warning: `%s' in quota blocks is 0 (unlimited).\n"), progname, s);
 		return 1;

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#1 lore raw
Quoted 9 lines · Eric Sandeen

Doing something like

# xfs_quota -x -c 'limit -u bhard=1.2g ...

will cause cvtnum to fail and return a value of -1LL (because it cannot parse the decimal), but the quota caller doesn't check for this error value, casts it to U64, shifts right, and we end up with an answer of 16 petabytes rather than erroring out. Fix this.

Can you add a test case for it, please?

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#2 lore raw
Quoted 5 lines · Christoph Hellwig
Quoted 4 lines · Eric Sandeen

Doing something like

# xfs_quota -x -c 'limit -u bhard=1.2g ...
Quoted 7 lines
Quoted 5 lines

will cause cvtnum to fail and return a value of -1LL (because it cannot parse the decimal), but the quota caller doesn't check for this error value, casts it to U64, shifts right, and we end up with an answer of 16 petabytes rather than erroring out. Fix this.

Can you add a test case for it, please?

sure... I have quite a backlog of tests I need to get pushed to git :(

Is that an ack for the patch, though? :)

-Eric

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#3 lore raw
In reply to Eric Sandeen

quota/edit.c extractb( · line 239

Quoted 8 lines
quota/edit.c +6 -2
-		v = (__uint64_t)cvtnum(blocksize, sectorsize, s);
-		*value = v >> 9;	/* syscalls use basic blocks */
+		v = cvtnum(blocksize, sectorsize, s);
+		if (v == -1LL) {
+			fprintf(stderr, _("%s: Error: could not parse size %s.\n"), progname, s);
+			return 0;
+		}
+		*value = (__uint64_t)v >> 8;	/* syscalls use basic blocks */

Why do you replace the shift by nine with a shift by 8?

Also please don't introduce new overly long lines, just move the translated string to a line of its own, indented by a single tab similar to how we do it in most new xfs/xfsprogs code.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#4 lore raw
Quoted 10 lines · Christoph Hellwig

quota/edit.c extractb( · line 239

Quoted 8 lines
quota/edit.c +6 -2
-		v = (__uint64_t)cvtnum(blocksize, sectorsize, s);
-		*value = v >> 9;	/* syscalls use basic blocks */
+		v = cvtnum(blocksize, sectorsize, s);
+		if (v == -1LL) {
+			fprintf(stderr, _("%s: Error: could not parse size %s.\n"), progname, s);
+			return 0;
+		}
+		*value = (__uint64_t)v >> 8;	/* syscalls use basic blocks */

Why do you replace the shift by nine with a shift by 8?

yeargh, NFI - vi gone wild?

Quoted 3 lines

Also please don't introduce new overly long lines, just move the translated string to a line of its own, indented by a single tab similar to how we do it in most new xfs/xfsprogs code.

Ok, sure, sorry. TBH I noticed it but there was such a long line below I didn't worry. Will resend.

-Eric

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

#5 lore raw

PATCH v2 1/1 xfsprogs: check for size parsing errors in xfs_quota

In reply to Christoph Hellwig

Doing something like

# xfs_quota -x -c 'limit -u bhard=1.2g ...

will cause cvtnum to fail and return a value of -1LL (because it cannot parse the decimal), but the quota caller doesn't check for this error value, casts it to U64, shifts right, and we end up with an answer of 16 petabytes rather than erroring out. Fix this.

---

V2: Fix mysterious change in shift size, shorten long line

quota/edit.c +9 -3
index b704e63..cad3aee 100644
@@ -226,13 +226,19 @@ extractb(
 	uint		sectorsize,
 	__uint64_t	*value)
 {
-	__uint64_t	v;
+	long long	v;
 	char		*s = string;
 
 	if (strncmp(string, prefix, length) == 0) {
 		s = string + length + 1;
-		v = (__uint64_t)cvtnum(blocksize, sectorsize, s);
-		*value = v >> 9;	/* syscalls use basic blocks */
+		v = cvtnum(blocksize, sectorsize, s);
+		if (v == -1LL) {
+			fprintf(stderr,
+				_("%s: Error: could not parse size %s.\n"),
+				progname, s);
+			return 0;
+		}
+		*value = (__uint64_t)v >> 9;	/* syscalls use basic blocks */
 		if (v > 0 && *value == 0)
 			fprintf(stderr, _("%s: Warning: `%s' in quota blocks is 0 (unlimited).\n"), progname, s);
 		return 1;

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

Reviewed-by on v2 1/1
#6 lore raw
Quoted 10 lines · Eric Sandeen

Doing something like

# xfs_quota -x -c 'limit -u bhard=1.2g ...

will cause cvtnum to fail and return a value of -1LL (because it cannot parse the decimal), but the quota caller doesn't check for this error value, casts it to U64, shifts right, and we end up with an answer of 16 petabytes rather than erroring out. Fix this.

Quoted 3 lines

---

Looks and works great.

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs