From mboxrd@z Thu Jan 1 00:00:00 1970 From: Julien Grall Subject: Re: [PATCH v3 04/24] xen: guestcopy: Provide an helper to safely copy string from guest Date: Tue, 20 Jan 2015 12:45:08 +0000 Message-ID: <54BE4DD4.8050602@linaro.org> References: <1421159133-31526-1-git-send-email-julien.grall@linaro.org> <1421159133-31526-5-git-send-email-julien.grall@linaro.org> <54BD44280200007800056A49@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YDYBe-0000YQ-JJ for xen-devel@lists.xenproject.org; Tue, 20 Jan 2015 12:45:38 +0000 Received: by mail-wi0-f182.google.com with SMTP id n3so21411128wiv.3 for ; Tue, 20 Jan 2015 04:45:37 -0800 (PST) In-Reply-To: <54BD44280200007800056A49@mail.emea.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: 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 Hi Jan, On 19/01/15 16:51, Jan Beulich wrote: >>>> On 13.01.15 at 15:25, wrote: >> --- /dev/null >> +++ b/xen/common/guestcopy.c >> @@ -0,0 +1,30 @@ >> +#include >> +#include >> +#include >> +#include >> + >> +/* The function copies a string from the guest and adds a NUL to >> + * make sure the string is correctly terminated. >> + */ > > Coding style. Ok. > >> +void *safe_copy_string_from_guest(XEN_GUEST_HANDLE(char) u_buf, >> + size_t size, size_t max_size) > > Is the "safe_" prefix really meaningful? I.e. is this function more > safe than e.g. copy_from_guest()? It's safe in the sense, the function adds a NUL to make sure the strings is correctly terminated. On the first v1, you said that name "copy_string_from_guest" doesn't match the behavior of the generic helper [1]. So which name do you suggest for this function? > >> +{ >> + char *tmp; >> + >> + if ( size > max_size ) >> + return ERR_PTR(-ENOENT); > > -ENOBUFS? I will use it. Regards, [1] http://lists.xen.org/archives/html/xen-devel/2014-06/msg02361.html -- Julien Grall