From: "Jan Beulich" Subject: Re: [RFC 02/19] xen: guestcopy: Provide an helper to copy string from guest Date: Tue, 17 Jun 2014 09:01:08 +0100 Message-ID: <53A011E4020000780001ADF4@mail.emea.novell.com> References: <1402935486-29136-1-git-send-email-julien.grall@linaro.org> <1402935486-29136-3-git-send-email-julien.grall@linaro.org> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WwoKN-0000ED-U8 for xen-devel@lists.xenproject.org; Tue, 17 Jun 2014 08:01:12 +0000 In-Reply-To: <1402935486-29136-3-git-send-email-julien.grall@linaro.org> 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: Julien Grall Cc: Keir Fraser , ian.campbell@citrix.com, tim@xen.org, Ian Jackson , stefano.stabellini@citrix.com, xen-devel@lists.xenproject.org, Daniel De Graaf List-Id: xen-devel@lists.xenproject.org >>> On 16.06.14 at 18:17, wrote: While generally I'm okay with adding such a helper, it should be done a little more cleanly I think: > --- /dev/null > +++ b/xen/common/guestcopy.c > @@ -0,0 +1,28 @@ > +#include > +#include > +#include > + > +int copy_string_from_guest(XEN_GUEST_HANDLE(char) u_buf, char **buf, > + unsigned long size, unsigned long max_size) Both of these ought to be size_t (as it was in the flask original). > +{ > + char *tmp; > + > + if ( size > max_size ) > + return -ENOENT; ENOBUFS would seem the better error code here. > + > + /* Add an extra +1 to append \0. We can't assume the guest will > + * provide a valid string */ Now this is the case for flask, but for a generic string copying routine I don't think this is desirable. It seems especially wrong to aid the guest with putting a NUL where none was. If you really want this, I guess you would be better off adding two variants: One which demands the string to be NUL-terminated (in which case passing in a size is sort of bogus), and one which takes a size and inserts a NUL. And in the end with the above I guess you realize why flask rolled its own special purpose function rather than adding a generic helper. Jan