From: "Jan Beulich" Subject: Re: [PATCH] sysctl: Don't overwrite array size variable when it is set on error earlier Date: Thu, 26 Mar 2015 08:32:41 +0000 Message-ID: <5513D239020000780006DC50@mail.emea.novell.com> References: <1427303386-3513-1-git-send-email-boris.ostrovsky@oracle.com> <5512EC66.1080009@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <5512EC66.1080009@citrix.com> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Andrew Cooper , Boris Ostrovsky Cc: keir@xen.org, tim@xen.org, ian.jackson@eu.citrix.com, ian.campbell@citrix.com, xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org >>> On 25.03.15 at 18:12, wrote: > On 25/03/15 17:09, Boris Ostrovsky wrote: >> When querying CPU topology, if caller-provided array size is smaller than >> number of online CPUs then, in addition to returning -ENOBUFS, sysctl is >> expected to provide back this number. However, this value, stored in 'i', >> is overwritten in the subsequent loop's control statement. >> >> Make sure we don't do this by converting the loop to 'while'. >> >> Signed-off-by: Boris Ostrovsky >> Reported-by: Andrew Cooper >> --- >> xen/common/sysctl.c | 6 +++++- >> 1 files changed, 5 insertions(+), 1 deletions(-) >> >> diff --git a/xen/common/sysctl.c b/xen/common/sysctl.c >> index a8c629f..b83d230 100644 >> --- a/xen/common/sysctl.c >> +++ b/xen/common/sysctl.c >> @@ -338,8 +338,10 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) > u_sysctl) >> ret = -ENOBUFS; >> i = num_cpus; >> } >> + else >> + i = 0; >> >> - for ( i = 0; i < num_cpus; i++ ) >> + while ( i < num_cpus ) > > This would be fine to keep as "for ( ; i < num_cpus; i++)", and helps > avoid an issue if someone introduces a continue; in the future. And that's also what I've been intending to change it to before committing. Jan