From da332b31effd204778ffc245184810f3b4137246 Mon Sep 17 00:00:00 2001 Message-Id: From: Bing Bu Cao Date: Tue, 10 Dec 2013 10:03:54 +0100 Subject: [PATCH] util: fix two virCompareLimitUlong bugs https://bugzilla.redhat.com/show_bug.cgi?id=1024272 The helper function virCompareLimitUlong compares limit values, where value of 0 is equal to unlimited. If the latter parameter is 0, it should return -1 instead of 1, hence the user can only set hard_limit when swap_hard_limit currently is unlimited. Worse, all callers pass 2 64-bit values, but on 32-bit platforms, the second argument was silently truncated to 32 bits, which could lead to incorrect computations. Signed-off-by: Bing Bu Cao Signed-off-by: Eric Blake (cherry picked from commit 19e7c04dce34afeb9a762471e09777de7d219db8) Signed-off-by: Jiri Denemark --- src/util/virutil.c | 5 ++++- src/util/virutil.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/util/virutil.c b/src/util/virutil.c index 21827f2..208d0b6 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -2030,11 +2030,14 @@ virFindFCHostCapableVport(const char *sysfs_prefix ATTRIBUTE_UNUSED) * Returns 0 if the numbers are equal, -1 if b is greater, 1 if a is greater. */ int -virCompareLimitUlong(unsigned long long a, unsigned long b) +virCompareLimitUlong(unsigned long long a, unsigned long long b) { if (a == b) return 0; + if (!b) + return -1; + if (a == 0 || a > b) return 1; diff --git a/src/util/virutil.h b/src/util/virutil.h index 2c8b0ec..2229c73 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -172,7 +172,7 @@ char *virGetFCHostNameByWWN(const char *sysfs_prefix, char *virFindFCHostCapableVport(const char *sysfs_prefix); -int virCompareLimitUlong(unsigned long long a, unsigned long b); +int virCompareLimitUlong(unsigned long long a, unsigned long long b); int virParseOwnershipIds(const char *label, uid_t *uidPtr, gid_t *gidPtr); -- 1.8.5.1