]> xenbits.xensource.com Git - people/pauldu/xen.git/commitdiff
sysctl: don't overwrite array size variable when it is set on error earlier
authorBoris Ostrovsky <boris.ostrovsky@oracle.com>
Thu, 26 Mar 2015 10:13:01 +0000 (11:13 +0100)
committerJan Beulich <jbeulich@suse.com>
Thu, 26 Mar 2015 10:13:01 +0000 (11:13 +0100)
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'.

Reported-by: Andrew Cooper <andrew.cooper3@citrix.com>
Signed-off-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/common/sysctl.c

index a8c629f38de9840b06fa1bbf3feb5b46ff2f3d7b..70413cc5c9fb8208b65f43d7b904449185a3bafe 100644 (file)
@@ -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++ )
+            for ( ; i < num_cpus; i++ )
             {
                 xen_sysctl_cputopo_t cputopo;