]> xenbits.xensource.com Git - libvirt.git/commitdiff
keepalive: Guard against integer overflow
authorJohn Ferlan <jferlan@redhat.com>
Tue, 5 Feb 2013 22:58:25 +0000 (17:58 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 20 Feb 2013 21:56:59 +0000 (16:56 -0500)
Don't allow interval to be > MAX_INT/1000 in virKeepAliveStart()

Guard against possible overflow in virKeepAliveTimeout() by setting the
timeout to be MAX_INT/1000 since the math following will multiply it by 1000.

src/rpc/virkeepalive.c

index d1fa642fd2bc902fefd805d533a8a2b2a20e936d..71dd904b38c0cddb91d6553ab128b3ea1c24326f 100644 (file)
@@ -252,6 +252,12 @@ virKeepAliveStart(virKeepAlivePtr ka,
                            _("keepalive interval already set"));
             goto cleanup;
         }
+        /* Guard against overflow */
+        if (interval > INT_MAX / 1000) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("keepalive interval %d too large"), interval);
+            goto cleanup;
+        }
         ka->interval = interval;
         ka->count = count;
         ka->countToDeath = count;
@@ -323,6 +329,9 @@ virKeepAliveTimeout(virKeepAlivePtr ka)
         timeout = ka->interval - (time(NULL) - ka->intervalStart);
         if (timeout < 0)
             timeout = 0;
+        /* Guard against overflow */
+        if (timeout > INT_MAX / 1000)
+            timeout = INT_MAX / 1000;
     }
 
     virObjectUnlock(ka);