Fix XAllocID race: hold the user display lock until we have a new XID.

Xlib built --without-xcb is also vulnerable to this race, and a similar
fix might work there too.

Also, use an XID that's truly invalid while waiting for the next XID to be
requested.
This commit is contained in:
Jamey Sharp 2008-03-23 16:33:50 -07:00
parent 54e5c0941b
commit cc19618d2e

View file

@ -343,6 +343,10 @@ _XIDHandler(Display *dpy)
{
XID next = xcb_generate_id(dpy->xcb->connection);
LockDisplay(dpy);
#ifdef XTHREADS
if (dpy->lock)
(*dpy->lock->user_unlock_display)(dpy);
#endif
dpy->xcb->next_xid = next;
if(dpy->flags & XlibDisplayPrivSync)
{
@ -357,8 +361,13 @@ _XIDHandler(Display *dpy)
/* _XAllocID - resource ID allocation routine. */
XID _XAllocID(Display *dpy)
{
const XID inval = ~0UL;
XID ret = dpy->xcb->next_xid;
dpy->xcb->next_xid = 0;
#ifdef XTHREADS
if (ret != inval && dpy->lock)
(*dpy->lock->user_lock_display)(dpy);
#endif
dpy->xcb->next_xid = inval;
if(!(dpy->flags & XlibDisplayPrivSync))
{