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

Re: [Xen-API] [Xen-devel] [PATCH 5 of 5 v3] tools/ocaml: libxc bindings: Fix failwith_xc()



This looks fine to me.

Cheers,
Dave

> -----Original Message-----
> From: xen-devel-bounces@xxxxxxxxxxxxx [mailto:xen-devel-
> bounces@xxxxxxxxxxxxx] On Behalf Of Andrew Cooper
> Sent: 12 March 2013 6:09 PM
> To: xen-devel@xxxxxxxxxxxxx
> Cc: Ian Jackson; Keir (Xen.org); Ian Campbell; Jan Beulich; xen-
> api@xxxxxxxxxxxxx
> Subject: [Xen-devel] [PATCH 5 of 5 v3] tools/ocaml: libxc bindings: Fix
> failwith_xc()
> 
> The static error_str[] buffer is not thread-safe, and 1024 bytes is
> unreasonably large.  Reduce to 256 bytes (which is still much larger than any
> current use), and move it to being a stack variable.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> 
> --
> Changes since v1:
>  * Mark as Noreturn, due to unconditional use of caml_raise_with_string()
> 
> diff -r 7a33b4fdb977 -r 189d76dca2e4 tools/ocaml/libs/xc/xenctrl_stubs.c
> --- a/tools/ocaml/libs/xc/xenctrl_stubs.c
> +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
> @@ -51,21 +51,22 @@
>       i1 = (uint32_t) Int64_val(Field(input, 0)); \
>       i2 = ((Field(input, 1) == Val_none) ? 0xffffffff : (uint32_t)
> Int64_val(Field(Field(input, 1), 0)));
> 
> -#define ERROR_STRLEN 1024
> -void failwith_xc(xc_interface *xch)
> +static void Noreturn failwith_xc(xc_interface *xch)
>  {
> -     static char error_str[ERROR_STRLEN];
> +     char error_str[256];
>       if (xch) {
>               const xc_error *error = xc_get_last_error(xch);
>               if (error->code == XC_ERROR_NONE)
> -                     snprintf(error_str, ERROR_STRLEN, "%d: %s", errno,
> strerror(errno));
> +                     snprintf(error_str, sizeof(error_str),
> +                              "%d: %s", errno, strerror(errno));
>               else
> -                     snprintf(error_str, ERROR_STRLEN, "%d: %s: %s",
> -                              error->code,
> +                     snprintf(error_str, sizeof(error_str),
> +                              "%d: %s: %s", error->code,
>                                xc_error_code_to_desc(error->code),
>                                error->message);
>       } else {
> -             snprintf(error_str, ERROR_STRLEN, "Unable to open XC
> interface");
> +             snprintf(error_str, sizeof(error_str),
> +                      "Unable to open XC interface");
>       }
>       caml_raise_with_string(*caml_named_value("xc.error"), error_str);  }
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@xxxxxxxxxxxxx
> http://lists.xen.org/xen-devel

_______________________________________________
Xen-api mailing list
Xen-api@xxxxxxxxxxxxx
http://lists.xen.org/cgi-bin/mailman/listinfo/xen-api


 


Rackspace

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