From: Stefano Stabellini Subject: Re: [PATCH v6 07/11] libxl: introduce libxl__alloc_vdev Date: Mon, 21 May 2012 18:50:14 +0100 Message-ID: References: <1337350125-30394-7-git-send-email-stefano.stabellini@eu.citrix.com> <20406.24419.849941.504507@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20406.24419.849941.504507@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: "xen-devel@lists.xensource.com" , Ian Campbell , Stefano Stabellini List-Id: xen-devel@lists.xenproject.org On Fri, 18 May 2012, Ian Jackson wrote: > Stefano Stabellini writes ("[PATCH v6 07/11] libxl: introduce libxl__alloc_vdev"): > > Introduce libxl__alloc_vdev: find a spare virtual block device in the > > domain passed as argument. > ... > > +/* Same as in Linux. > > + * The maximum buffer length is 32 bytes. > > + * The code is safe thanks to the upper bound enforced by the caller. */ > > +static char *encode_disk_name(char *ptr, unsigned int n) > > So this says that encode_disk_name may use up to 32 bytes in *ptr > (including or excluding the trailing nul?) > > _Why_ may the maximum buffer length used be 32 bytes ? Also, "maximum > buffer length" is a confusing phrase because it seems to refer to the > /actual/ length of the buffer rather than the amount /used/. > > And this... > > > + char *ret = libxl__zalloc(gc, 32); > > ... allocates a 32 byte buffer which we then fill with ... > > > + strcpy(ret, "xvd"); > > + ptr = encode_disk_name(ret + 3, offset); > > 3 characters plus the encoded disk name. So possibly using up to 36 > bytes. > > In fact it seems to me that there could be a much tighter upper bound > on the length of output of encode_disk_name (based on arithmetic) but > it needs to be properly calculated and documented and perhaps put in a > #define. If my math is correct there is no need to enforce an upper limit because even if we suppose that offset is ULONG_MAX on 64 bits it would still be lower than 26 elevated at 28 that is the actual upper limit. I am going to write this in a comment.