[libvirt] [PATCH 02/11] keepalive: Resolve Coverity complaint

Eric Blake eblake at redhat.com
Thu Jan 31 23:16:36 UTC 2013


On 01/30/2013 12:36 PM, John Ferlan wrote:
> The Coverity analysis emitted a BAD_SIZEOF error when doing the math
> within the TRACE macro. Doing the math outside the macro keeps Coverity quiet.
> ---
>  src/rpc/virkeepalive.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 

>      time_t now = time(NULL);
> +    int timeval;
>  
>      if (ka->interval <= 0 || ka->intervalStart == 0)
>          return false;
>  
>      if (now - ka->intervalStart < ka->interval) {
> -        int timeout = ka->interval - (now - ka->intervalStart);
> -        virEventUpdateTimeout(ka->timer, timeout * 1000);
> +        timeval = ka->interval - (now - ka->intervalStart);
> +        virEventUpdateTimeout(ka->timer, timeval * 1000);
>          return false;

Eww - pre-existing bug, but we have the potential for multiplication
overflow, and for truncation if time_t is wider than int.  We probably
ought to do a followup code to make this math more robust (by rejecting
any timeval input from the user that exceeds MAX_INT/1000).  But that
doesn't affect Osier's ACK for this patch.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130131/d9281aaa/attachment-0001.sig>


More information about the libvir-list mailing list