From: Ian Jackson Subject: Re: [PATCH v6 07/11] libxl: introduce libxl__alloc_vdev Date: Fri, 18 May 2012 15:40:35 +0100 Message-ID: <20406.24419.849941.504507@mariner.uk.xensource.com> References: <1337350125-30394-7-git-send-email-stefano.stabellini@eu.citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1337350125-30394-7-git-send-email-stefano.stabellini@eu.citrix.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: Stefano Stabellini Cc: "xen-devel@lists.xensource.com" , Ian Campbell List-Id: xen-devel@lists.xenproject.org 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. Ian.