]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: fix two virCompareLimitUlong bugs
authorBing Bu Cao <mars@linux.vnet.ibm.com>
Fri, 11 Oct 2013 06:50:33 +0000 (14:50 +0800)
committerEric Blake <eblake@redhat.com>
Fri, 11 Oct 2013 12:34:18 +0000 (06:34 -0600)
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 <mars@linux.vnet.ibm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
src/util/virutil.c
src/util/virutil.h

index d9e0bc4a42b814c6539c8f85a554854e065d1684..854c0ad5ec365ff6dce9d9d1a5bfc1ebfc5d148d 100644 (file)
@@ -2062,11 +2062,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;
 
index 4b06992346d853b02b49a200bb9f60e2832ddf66..9f6fb200a4864bf94a78f806f635acdff1bf5d22 100644 (file)
@@ -168,7 +168,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);