Blame SOURCES/quota-4.02-Fix-handling-of-space-and-inode-values.patch

370c56
From 663ac451b045b4823d6d633893a5d748c09f42f2 Mon Sep 17 00:00:00 2001
370c56
From: Jan Kara <jack@suse.cz>
370c56
Date: Wed, 1 Oct 2014 18:10:40 +0200
370c56
Subject: [PATCH] Fix handling of space and inode values
370c56
MIME-Version: 1.0
370c56
Content-Type: text/plain; charset=UTF-8
370c56
Content-Transfer-Encoding: 8bit
370c56
370c56
Commit 0214512479e0 (Properly handle signed space and inode values)
370c56
broke parsing of pure numbers in str2number() so that it would always
370c56
complain about "Integer overflow while interpreting decimal unit". Fix
370c56
condition checking for overflow.
370c56
370c56
Also number2str() was buggy and wouldn't guess proper units for negative
370c56
numbers.
370c56
370c56
Signed-off-by: Jan Kara <jack@suse.cz>
370c56
Signed-off-by: Petr Písař <ppisar@redhat.com>
370c56
---
370c56
 quotasys.c | 16 +++++++++-------
370c56
 1 file changed, 9 insertions(+), 7 deletions(-)
370c56
370c56
diff --git a/quotasys.c b/quotasys.c
370c56
index a5737a8..4b49e0e 100644
370c56
--- a/quotasys.c
370c56
+++ b/quotasys.c
370c56
@@ -459,17 +459,19 @@ void number2str(long long num, char *buf, int format)
370c56
 	int i;
370c56
 	unsigned long long div;
370c56
 	char suffix[8] = " kmgt";
370c56
-	long long anum = num >= 0 ? num : -num;
370c56
 
370c56
-	if (format)
370c56
-		for (i = 4, div = 1000000000000LL; i > 0; i--, div /= 1000)
370c56
-			if (num >= 100*div) {
370c56
-				int sign = num != anum ? -1 : 1;
370c56
+	if (format) {
370c56
+		long long anum = num >= 0 ? num : -num;
370c56
+		int sign = num != anum ? -1 : 1;
370c56
 
370c56
-				sprintf(buf, "%lld%c", (num+div-1) / div * sign,
370c56
+		for (i = 4, div = 1000000000000LL; i > 0; i--, div /= 1000)
370c56
+			if (anum >= 100*div) {
370c56
+				sprintf(buf, "%lld%c",
370c56
+					DIV_ROUND_UP(anum, div) * sign,
370c56
 					suffix[i]);
370c56
 				return;
370c56
 			}
370c56
+	}
370c56
 	sprintf(buf, "%lld", num);
370c56
 }
370c56
 
370c56
@@ -500,7 +502,7 @@ const char *str2number(const char *string, qsize_t *inodes)
370c56
 		return _("Unknown decimal unit. "
370c56
 			"Valid units are k, m, g, t.");
370c56
 	if (number > QSIZE_MAX / multiple ||
370c56
-	    -number < QSIZE_MAX / multiple)
370c56
+	    number < -(QSIZE_MAX / multiple))
370c56
 		return _("Integer overflow while interpreting decimal unit.");
370c56
 	*inodes = number * multiple;
370c56
 	return NULL;
370c56
-- 
370c56
1.9.3
370c56