[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] tools/xl: Fix trim() following c/s e316316 "xl: Rewrite trim()"



On Thu, Jul 16, 2015 at 08:18:31PM +0100, Andrew Cooper wrote:
> c/s e316316 "xl: Rewrite trim()" uses the wrong indirection of
> 'output', causing memory corruption for all callers.
> 
> Introduce a new local variable, making the code more obviously
> correct.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> CC: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
> CC: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
> CC: Wei Liu <wei.liu2@xxxxxxxxxx>

Acked-by: Wei Liu <wei.liu2@xxxxxxxxxx>

One nit below.

> ---
>  tools/libxl/xl_cmdimpl.c |    8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index 37d4af6..0cc9f8b 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -663,10 +663,12 @@ static void trim(char_predicate_t predicate, const char 
> *input, char **output)
>          ;
>  
>      size_t len_nonnull = after - first;
> +    char *result = xmalloc(len_nonnull + 1);
>  

Can you move the declaration of result to the beginning of this
function?

> -    *output = xmalloc(len_nonnull + 1);
> -    memcpy(output, first, len_nonnull);
> -    output[len_nonnull] = 0;
> +    memcpy(result, first, len_nonnull);
> +    result[len_nonnull] = 0;
> +
> +    *output = result;
>  }
>  
>  static int split_string_into_pair(const char *str,
> -- 
> 1.7.10.4

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.