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

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