[PATCH] server: move memset after check

Marek Chalupa mchqwerty at gmail.com
Wed Aug 6 02:28:12 PDT 2014


I meant to send it normally, not in reply to the previous bug, I'll 
resend it.

On 08/06/14 11:23, Marek Chalupa wrote:
> If the malloc fails, memset would touch invalid memory.
> ---
>   src/wayland-server.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/src/wayland-server.c b/src/wayland-server.c
> index 75de313..3c162d4 100644
> --- a/src/wayland-server.c
> +++ b/src/wayland-server.c
> @@ -1150,10 +1150,11 @@ wl_display_add_socket_auto(struct wl_display *display)
>   	const int MAX_DISPLAYNO = 32;
>   
>   	s = malloc(sizeof *s);
> -	memset(s, 0, sizeof *s);
>   	if (s == NULL)
>   		return NULL;
>   
> +	memset(s, 0, sizeof *s);
> +
>   	do {
>   		snprintf(display_name, sizeof display_name, "wayland-%d", displayno);
>   		if (wl_socket_init_for_display_name(s, display_name) < 0) {



More information about the wayland-devel mailing list