From: Ian Jackson Subject: Re: [PATCH] libxl: don't accept negative disk or partition indexes Date: Tue, 13 Mar 2012 17:23:54 +0000 Message-ID: <20319.33450.71437.492223@mariner.uk.xensource.com> References: <4F574E370200007800076E23@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <4F574E370200007800076E23@nat28.tlf.novell.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: Jan Beulich Cc: xen-devel List-Id: xen-devel@lists.xenproject.org Jan Beulich writes ("[Xen-devel] [PATCH] libxl: don't accept negative disk or partition indexes"): > When obtained via sscanf(), they were checked against an upper bound > only so far. By converting the local variables' types to "unsigned int" > those bounds checks become sufficient (as a consequence the helper > function's parameter types need to be adjusted too). It's not strictly > necessary to also convert libxl__device_disk_dev_number()'s parameter > types - the bounds checking done (now) guarantees that the values won't > run into the negative range of "int" values. IMO "unsigned int" is not a type that should be used for things which are like mathematical integers, even if their range happens to include only non-negative integers. In C unsigned types have some very surprising behaviours in comparisons and subtractions. So I think the correct thing to do is to check that the values are within sensible limits after sscanf returns. Ian.