[PATCH] server: move memset after check

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


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) {
-- 
2.0.4



More information about the wayland-devel mailing list