[PATCH] Fix re-entrancy issues in wl_display_iterate().

Hannu Lyytinen hannu.lyytinen at nomovok.com
Wed Apr 11 23:51:23 PDT 2012


This fixes a possible re-entrancy issue in case of nested requests.

---
 src/connection.c      |    8 +++++++-
 src/wayland-client.c  |    6 ++++--
 src/wayland-private.h |    1 +
 3 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/connection.c b/src/connection.c
index 2795481..c5c9c77 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -259,6 +259,12 @@ decode_cmsg(struct wl_buffer *buffer, struct msghdr *msg)
 }
 
 int
+wl_connection_data_length(struct wl_connection *connection)
+{
+	return connection->in.head - connection->in.tail;
+}
+
+int
 wl_connection_data(struct wl_connection *connection, uint32_t mask)
 {
 	struct iovec iov[2];
@@ -335,7 +341,7 @@ wl_connection_data(struct wl_connection *connection, uint32_t mask)
 		connection->in.head += len;
 	}	
 
-	return connection->in.head - connection->in.tail;
+	return wl_connection_data_length(connection);
 }
 
 int
diff --git a/src/wayland-client.c b/src/wayland-client.c
index 9057b4f..0bf8c81 100644
--- a/src/wayland-client.c
+++ b/src/wayland-client.c
@@ -509,9 +509,11 @@ wl_display_iterate(struct wl_display *display, uint32_t mask)
 		return;
 	}
 
-	len = wl_connection_data(display->connection, mask);
+	wl_connection_data(display->connection, mask);
+
+	for (;;) {
+		len = wl_connection_data_length(display->connection);
 
-	while (len > 0) {
 		if ((size_t) len < sizeof p)
 			break;
 		
diff --git a/src/wayland-private.h b/src/wayland-private.h
index b843e89..416f4af 100644
--- a/src/wayland-private.h
+++ b/src/wayland-private.h
@@ -65,6 +65,7 @@ void wl_connection_destroy(struct wl_connection *connection);
 void wl_connection_copy(struct wl_connection *connection, void *data, size_t size);
 void wl_connection_consume(struct wl_connection *connection, size_t size);
 int wl_connection_data(struct wl_connection *connection, uint32_t mask);
+int wl_connection_data_length(struct wl_connection *connection);
 int wl_connection_write(struct wl_connection *connection, const void *data, size_t count);
 int wl_connection_queue(struct wl_connection *connection,
 			const void *data, size_t count);
-- 
1.7.1



More information about the wayland-devel mailing list