xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: wei.liu2@citrix.com, stefano.stabellini@eu.citrix.com,
	Jennifer Herbert <Jennifer.Herbert@citrix.com>,
	xen-devel@lists.xen.org
Subject: Re: [PATCH 1/7] libxc: fix uninitialized variable in xc_cpuid_pv_policy()
Date: Fri, 3 Jul 2015 16:39:16 +0100	[thread overview]
Message-ID: <1435937956.9447.165.camel@citrix.com> (raw)
In-Reply-To: <21910.42740.702016.879273@mariner.uk.xensource.com>

On Fri, 2015-07-03 at 16:15 +0100, Ian Jackson wrote:
> Jennifer Herbert writes ("[Xen-devel] [PATCH 1/7] libxc: fix uninitialized variable in xc_cpuid_pv_policy()"):
> > If xc_domain_get_guest_width were to fail, guest_width is not set, and
> > hence guest_64bit becomes undefined.
> > Fix is to initialise to 0, and report error if call fails.
> ...
> > diff --git a/tools/libxc/xc_cpuid_x86.c b/tools/libxc/xc_cpuid_x86.c
> > index c97f91a..847b701 100644
> > --- a/tools/libxc/xc_cpuid_x86.c
> > +++ b/tools/libxc/xc_cpuid_x86.c
> > @@ -437,14 +437,16 @@ static void xc_cpuid_pv_policy(
> >  {
> >      DECLARE_DOMCTL;
> >      unsigned int guest_width;
> > -    int guest_64bit;
> > +    int guest_64bit = 0;
> 
> I'm not a huge fan of this style, which some people might describe as
> `defensive initialisations'.  They turn failures to initialise a
> variable (which can be detected by tools like Coverity and some
> compilers), into uses of the wrong value.
> 
> > -    xc_domain_get_guest_width(xch, domid, &guest_width);
> > -    guest_64bit = (guest_width == 8);
> > +    if (xc_domain_get_guest_width(xch, domid, &guest_width) == 0)
> > +        guest_64bit = (guest_width == 8);
> > +    else
> > +        ERROR("Could not read guest word width.");
> 
> Surely after failure of xc_domain_get_guest_width we should not
> blunder on, making unwarranted assumptions about the guest bit width.
> 
> Unfortunately xc_cpuid_pv_policy doesn't return an error code.  I
> think it needs to.  So that's rather a yak.

I was about to say it's not one worth shaving, but actually although
this returns void it is static and has exactly one caller which can
return errors -- so it's a very easy yakk to shave it seems.

Ian.

  reply	other threads:[~2015-07-03 15:39 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-01 17:37 [PATCH 0/7] libxc: Fix a number of coverity issues Jennifer Herbert
2015-07-01 17:37 ` [PATCH 1/7] libxc: fix uninitialized variable in xc_cpuid_pv_policy() Jennifer Herbert
2015-07-02 13:19   ` Andrew Cooper
2015-07-03 14:39   ` Andrew Cooper
2015-07-03 15:15   ` Ian Jackson
2015-07-03 15:39     ` Ian Campbell [this message]
2015-07-03 15:47       ` Ian Jackson
2015-07-03 15:50         ` Ian Campbell
2015-07-03 15:57           ` Andrew Cooper
2015-07-01 17:37 ` [PATCH 2/7] libxc: Use const pointer in local_file_dump() Jennifer Herbert
2015-07-03 15:27   ` Ian Jackson
2015-07-07 12:16     ` Jennifer Herbert
2015-07-07 12:15       ` Ian Jackson
2015-07-01 17:37 ` [PATCH 3/7] libxc: Fix uninitialized valiables in xc_cpuid_hvm_policy() Jennifer Herbert
2015-07-03 15:30   ` Ian Jackson
2015-07-01 17:37 ` [PATCH 4/7] libxc: Prevent dereferencing NULL pointers returned from xc_dom_allocate() Jennifer Herbert
2015-07-03 15:17   ` Ian Jackson
2015-07-03 16:01     ` Ian Campbell
2015-07-01 17:37 ` [PATCH 5/7] libxc: Removing dead code " Jennifer Herbert
2015-07-03 14:41   ` Andrew Cooper
2015-07-03 15:24   ` Ian Jackson
2015-07-03 15:31     ` Ian Campbell
2015-07-03 15:33       ` Ian Jackson
2015-07-03 15:46         ` Ian Campbell
2015-07-03 15:48           ` Ian Jackson
2015-07-01 17:37 ` [PATCH 6/7] libxc: Fix misleading use of strncpy code in build_hvm_info() Jennifer Herbert
2015-07-03 14:41   ` Andrew Cooper
2015-07-03 15:25   ` Ian Jackson
2015-07-03 16:01     ` Ian Campbell
2015-07-01 17:37 ` [PATCH 7/7] libxc: Prevent NULL pointer dereference in stdiostream_vmessage() Jennifer Herbert
2015-07-03 15:29   ` Ian Jackson
2015-07-03 15:37     ` Ian Campbell
2015-07-03 15:44       ` Ian Jackson
2015-07-02 13:23 ` [PATCH 0/7] libxc: Fix a number of coverity issues Andrew Cooper
2015-07-03 14:21   ` Ian Campbell
2015-07-03 14:20 ` Ian Campbell
2015-07-03 14:22   ` Andrew Cooper
2015-07-03 14:42     ` Ian Campbell
2015-07-03 14:49       ` Andrew Cooper
2015-07-03 15:13 ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1435937956.9447.165.camel@citrix.com \
    --to=ian.campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=Jennifer.Herbert@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).