From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ian Campbell Subject: Re: [PATCH 1/7] libxc: fix uninitialized variable in xc_cpuid_pv_policy() Date: Fri, 3 Jul 2015 16:39:16 +0100 Message-ID: <1435937956.9447.165.camel@citrix.com> References: <1435772232-39085-1-git-send-email-Jennifer.Herbert@citrix.com> <1435772232-39085-2-git-send-email-Jennifer.Herbert@citrix.com> <21910.42740.702016.879273@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <21910.42740.702016.879273@mariner.uk.xensource.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Ian Jackson Cc: wei.liu2@citrix.com, stefano.stabellini@eu.citrix.com, Jennifer Herbert , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org 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.