Re: [libvirt] [PATCH] avoid a probable EINVAL from lseek

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Feb 01, 2010 at 10:18:27PM +0100, Jim Meyering wrote:
> 
> In src/qemu/qemu_driver.c, coverity reports this:
> 
>   Event negative_return_fn: Called negative-returning function "lseek(logfile, 0L, 2)"
>   Event var_assign: NEGATIVE return value of "lseek" assigned to signed variable "pos"
>   At conditional (1): "(pos = lseek(logfile, 0L, 2)) < 0" taking true path
>   2877 	    if ((pos = lseek(logfile, 0, SEEK_END)) < 0)
>   2878 	        VIR_WARN(_("Unable to seek to end of logfile: %s"),
>   2879 	                 virStrerror(errno, ebuf, sizeof ebuf));

I think it'd be less surprising to just set 'pos = 0' inside the if
branch here, so later code doesn't have to worry about unexpected
negative values.

> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 22593bf..676a27b 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -558,8 +558,8 @@ qemudLogReadFD(virConnectPtr conn, const char* logDir, const char* name, off_t p
>          close(fd);
>          return -1;
>      }
> -    if (lseek(fd, pos, SEEK_SET) < 0) {
> -        virReportSystemError(conn, errno,
> +    if (pos < 0 || lseek(fd, pos, SEEK_SET) < 0) {
> +      virReportSystemError(conn, pos < 0 ? 0 : errno,
>                               _("Unable to seek to %lld in %s"),
>                               (long long) pos, logfile);
>          close(fd);
> --

Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]