File U_0003-poll_for_response-Call-poll_for_event-again-if-xcb_p.patch of Package libX11.26493

From 406afe4b0f1b655c0db19bbc9a0c48da9a46acf5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Michel=20D=C3=A4nzer?= <michel.daenzer@amd.com>
Date: Tue, 25 Sep 2018 17:10:58 +0200
Subject: [PATCH 3/6] poll_for_response: Call poll_for_event again if
 xcb_poll_for_reply fails

If xcb_poll_for_reply fails to find a reply, poll_for_response would
always return NULL. However, xcb_poll_for_reply may have read events
from the display connection while looking for a reply. In that case,
returning NULL from poll_for_response is wrong and can result in the
client hanging, e.g. because it returns to waiting for the display
connection file descriptor becoming readable after XPending incorrectly
returned 0 pending events.

The solution is to call poll_for_event again after xcb_poll_for_reply
returned 0. This will return the first of any events read by
xcb_poll_for_reply.

Fixes issue #79.

Reported-by: Yuxuan Shui <yshuiv7@gmail.com>
Bugzilla: https://bugs.freedesktop.org/108008
Bugzilla: https://bugs.freedesktop.org/107992
Reviewed-by: Adam Jackson <ajax@redhat.com>
---
 src/xcb_io.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/xcb_io.c b/src/xcb_io.c
index 649c8200..a32b7d75 100644
--- a/src/xcb_io.c
+++ b/src/xcb_io.c
@@ -273,10 +273,19 @@ static xcb_generic_reply_t *poll_for_response(Display *dpy)
 	PendingRequest *req;
 	while(!(response = poll_for_event(dpy)) &&
 	      (req = dpy->xcb->pending_requests) &&
-	      !req->reply_waiter &&
-	      xcb_poll_for_reply64(dpy->xcb->connection, req->sequence, &response, &error))
+	      !req->reply_waiter)
 	{
-		uint64_t request = X_DPY_GET_REQUEST(dpy);
+		uint64_t request;
+
+		if(!xcb_poll_for_reply64(dpy->xcb->connection, req->sequence,
+					 &response, &error)) {
+			/* xcb_poll_for_reply64 may have read events even if
+			 * there is no reply. */
+			response = poll_for_event(dpy);
+			break;
+		}
+
+		request = X_DPY_GET_REQUEST(dpy);
 		if(XLIB_SEQUENCE_COMPARE(req->sequence, >, request))
 		{
 			throw_thread_fail_assert("Unknown sequence number "
-- 
2.16.4

openSUSE Build Service is sponsored by