From amiga!oliveb!ames!garp!mit-eddie!expo.lcs.mit.edu!bugs Thu Mar  8 14:39:57 1990
Received: by cbmvax.cbm.commodore.com (5.57/UUCP-Project/Commodore Jan 13 1990)
	id AA22107; Thu, 8 Mar 90 14:39:54 EST
Received: by amiga.uucp (1.1/3.14)
	id AA15565; Thu, 8 Mar 90 11:34:00 PST
Received: by boing.com (3.2/SMI-3.2)
	id AA04220; Thu, 8 Mar 90 10:41:10 PST
Received: by amiga.uucp (1.1/3.14)
	id AA09877; Thu, 8 Mar 90 07:39:05 PST
Received: by oliveb.OLIVETTI.COM (smail2.5)
	id AA06771; 8 Mar 90 06:41:43 PST (Thu)
Received: by ames.arc.nasa.gov (5.61/1.2); Thu, 8 Mar 90 06:40:49 -0800
Received: by GARP.MIT.EDU with sendmail-5.61/4.7 
	id <AA04860@GARP.MIT.EDU>; Thu, 8 Mar 90 09:11:33 -0500
Received: from EXPO.LCS.MIT.EDU by EDDIE.MIT.EDU with SMTP (5.61/25-eef)
	id AA18181; Thu, 8 Mar 90 08:54:14 EST
Received: by expo.lcs.mit.edu; Thu, 8 Mar 90 08:42:24 EST
Date: Thu, 8 Mar 90 08:42:24 EST
From: amiga!GARP.MIT.EDU!mit-eddie!expo.lcs.mit.edu!bugs (Bug Reports)
Message-Id: <9003081342.AA06785@expo.lcs.mit.edu>
To: bug-trackers@expo.lcs.mit.edu
Subject: XBUG #2690:  server can coredump due to thaws
Status: R

(Message inbox:458)
Return-Path: mouse@larry.mcrcim.mcgill.edu
Received: from Larry.McRCIM.McGill.EDU by expo.lcs.mit.edu; Wed, 7 Mar 90 14:21:55 EST
Received: by Larry.McRCIM.McGill.EDU (5.61)
	id <9003071922.AA00658@Larry.McRCIM.McGill.EDU>; Wed, 7 Mar 90 14:22:49 -0500
Date: Wed, 7 Mar 90 14:22:49 -0500
From: der Mouse  <mouse@larry.mcrcim.mcgill.edu>
Message-Id: <9003071922.AA00658@Larry.McRCIM.McGill.EDU>
To: xbugs@expo.lcs.mit.edu
Subject: server can coredump due to thaws
Cc: xpert%expo.lcs.mit.edu@athena.mit.edu

### bug number:   2690
### area:         server
### severity:     very high
### comments:     fix is suboptimal

			  X Window System Bug Report
			    xbugs@expo.lcs.mit.edu


VERSION:
    R4

CLIENT MACHINE and OPERATING SYSTEM:
    any

DISPLAY TYPE:
    any

WINDOW MANAGER:
    any

AREA:
    server

SYNOPSIS:
    Under certain circumstances, PlayReleasedEvents can free a
    QdEventRec that is still being pointed to.

DESCRIPTION:
    The queue of events waiting for a freeze to be thawed has a tail
    pointer, which is used for two things: (1) to append quickly to the
    tail of the queue and (2) to collapse consecutive MotionNotify
    events.  However, PlayReleasedEvents doesn't check carefully
    enough, and if syncEvents.pendtail points into the next-to-last
    event, and PlayReleasedEvents replays the next-to-last event but
    not the last, syncEvents.pendtail will be left pointing into a
    freed block of memory.

REPEAT BY:
    The simplest thing is to examine the code.  It is possible to
    create this condition from clients, but I do not know precisely
    what does it.  I suspect that changing focus while the keyboard is
    frozen may do it.

SAMPLE FIX:

    The patch given below changes the meaning of syncEvents.pendtail to
    be nothing but a pointer to the last pointer in the list, thus
    simplifying the code to maintain and use it (and making it more
    understandable thereby).  A new field, syncEvents.tail, is created
    to serve the other function, allowing MotionNotify event collapsing.

    This patch also includes two enhancements to os/4.2bsd/utils.c:

    - If gcc 1.37.1 is used to build the server on a Sun-3 running
      release 3.5 (and possibly other compilers or platforms) with
      MEMBUG defined, MemoryValidate is defined but it goes in the bss
      segment, making it impossible to use adb to set it in the
      executable file.  The patch initializes it to zero, which (at
      least under the above combination) puts it in the data segment
      instead, where it can be patched with adb.

    - When MEMBUG is defined, the entire contents of any block passed
      to Xfree will be overwritten with 'Z' bytes.  This greatly
      increases the probability of catching a use-after-free bug (such
      as the main one in this report) early.

    *** /@apollo/u3/X11R4/mit/server/dix/events.c	Wed Jan 24 10:17:52 1990
    --- mit/server/dix/events.c	Wed Mar  7 12:46:44 1990
    ***************
    *** 90,95 ****
    --- 90,96 ----
      
      static struct {
          QdEventPtr		pending, *pendtail;
    +     QdEventPtr		tail;
          DeviceIntPtr	replayDev;	/* kludgy rock to put flag for */
          WindowPtr		replayWin;	/*   ComputeFreezes            */
          Bool		playingEvents;
    ***************
    *** 482,488 ****
          DeviceIntPtr	device;
          int			count;
      {
    -     register QdEventPtr tail = *syncEvents.pendtail;
          register QdEventPtr qe;
          xEvent		*qxE;
      
    --- 483,488 ----
    ***************
    *** 492,503 ****
      	sprite.hotPhys.x = xE->u.keyButtonPointer.rootX;
      	sprite.hotPhys.y = xE->u.keyButtonPointer.rootY;
      	/* do motion compression */
    ! 	if (tail &&
    ! 	    (tail->event->u.u.type == MotionNotify) &&
    ! 	    (tail->pScreen == sprite.hotPhys.pScreen))
      	{
    ! 	    tail->event->u.keyButtonPointer.rootX = sprite.hotPhys.x;
    ! 	    tail->event->u.keyButtonPointer.rootY = sprite.hotPhys.y;
      	    return;
      	}
          }
    --- 492,503 ----
      	sprite.hotPhys.x = xE->u.keyButtonPointer.rootX;
      	sprite.hotPhys.y = xE->u.keyButtonPointer.rootY;
      	/* do motion compression */
    ! 	if (syncEvents.tail &&
    ! 	    (syncEvents.tail->event->u.u.type == MotionNotify) &&
    ! 	    (syncEvents.tail->pScreen == sprite.hotPhys.pScreen))
      	{
    ! 	    syncEvents.tail->event->u.keyButtonPointer.rootX = sprite.hotPhys.x;
    ! 	    syncEvents.tail->event->u.keyButtonPointer.rootY = sprite.hotPhys.y;
      	    return;
      	}
          }
    ***************
    *** 512,520 ****
          qe->evcount = count;
          for (qxE = qe->event; --count >= 0; qxE++, xE++)
      	*qxE = *xE;
    -     if (tail)
    - 	syncEvents.pendtail = &tail->next;
          *syncEvents.pendtail = qe;
      }
      
      static void
    --- 512,520 ----
          qe->evcount = count;
          for (qxE = qe->event; --count >= 0; qxE++, xE++)
      	*qxE = *xE;
          *syncEvents.pendtail = qe;
    +     syncEvents.tail = qe;
    +     syncEvents.pendtail = &qe->next;
      }
      
      static void
    ***************
    *** 529,535 ****
    --- 529,540 ----
      	{
      	    *prev = qe->next;
      	    if (!qe->next)
    + 	    {
      		syncEvents.pendtail = prev;
    + 		syncEvents.tail = 0;
    + 	    }
    + 	    if (qe == syncEvents.tail)
    + 		FatalError("PlayReleasedEvents: tail pointer wrong");
      	    if (qe->event->u.u.type == MotionNotify)
      		CheckVirtualMotion(qe, NullWindow);
      	    syncEvents.time.months = qe->months;
    ***************
    *** 2883,2888 ****
    --- 2888,2895 ----
          sprite.hotLimits.x2 = 0;
          sprite.hotLimits.y2 = 0;
          syncEvents.replayDev = (DeviceIntPtr)NULL;
    +     syncEvents.pendtail = &syncEvents.pending;
    +     syncEvents.tail = 0;
          while (syncEvents.pending)
          {
      	QdEventPtr next = syncEvents.pending->next;
    ***************
    *** 2889,2895 ****
      	xfree(syncEvents.pending);
      	syncEvents.pending = next;
          }
    -     syncEvents.pendtail = &syncEvents.pending;
          syncEvents.playingEvents = FALSE;
          currentTime.months = 0;
          currentTime.milliseconds = GetTimeInMillis();
    --- 2896,2901 ----
    

    *** /@apollo/u3/X11R4/mit/server/os/4.2bsd/utils.c	Thu Jan 11 13:12:40 1990
    --- mit/server/os/4.2bsd/utils.c	Wed Mar  7 13:06:35 1990
    ***************
    *** 431,437 ****
      unsigned long	MemoryAllocTime;
      unsigned long	MemoryAllocBreakpoint = ~0;
      unsigned long	MemoryActive = 0;
    ! unsigned long	MemoryValidate;
      
      MallocHeaderPtr	MemoryInUse;
      
    --- 431,437 ----
      unsigned long	MemoryAllocTime;
      unsigned long	MemoryAllocBreakpoint = ~0;
      unsigned long	MemoryActive = 0;
    ! unsigned long	MemoryValidate = 0;
      
      MallocHeaderPtr	MemoryInUse;
      
    ***************
    *** 604,612 ****
    --- 604,615 ----
          if (ptr)
          {
      	MallocHeaderPtr head;
    + 	register char *cp;
    + 	register int n;
      
      	CheckNode(ptr);
      	head = Header(ptr);
    + 	for (cp=(char *)ptr,n=(int)head->amount;n>0;n--,cp++) *cp = 'Z';
      	head->magic = FREEDMAGIC;
      	free ((char *) head);
          }
    
    
					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu


From amiga!oliveb!ames!garp!mit-eddie!expo.lcs.mit.edu!bugs Thu Mar  8 14:40:01 1990
Received: by cbmvax.cbm.commodore.com (5.57/UUCP-Project/Commodore Jan 13 1990)
	id AA22123; Thu, 8 Mar 90 14:39:59 EST
Received: by amiga.uucp (1.1/3.14)
	id AA15586; Thu, 8 Mar 90 11:34:36 PST
Received: by boing.com (3.2/SMI-3.2)
	id AA04226; Thu, 8 Mar 90 10:41:22 PST
Received: by amiga.uucp (1.1/3.14)
	id AA09884; Thu, 8 Mar 90 07:39:14 PST
Received: by oliveb.OLIVETTI.COM (smail2.5)
	id AA06776; 8 Mar 90 06:41:50 PST (Thu)
Received: by ames.arc.nasa.gov (5.61/1.2); Thu, 8 Mar 90 06:40:57 -0800
Received: by GARP.MIT.EDU with sendmail-5.61/4.7 
	id <AA04870@GARP.MIT.EDU>; Thu, 8 Mar 90 09:11:46 -0500
Received: from EXPO.LCS.MIT.EDU by EDDIE.MIT.EDU with SMTP (5.61/25-eef)
	id AA18233; Thu, 8 Mar 90 08:54:39 EST
Received: by expo.lcs.mit.edu; Thu, 8 Mar 90 08:40:48 EST
Date: Thu, 8 Mar 90 08:40:48 EST
From: amiga!GARP.MIT.EDU!mit-eddie!expo.lcs.mit.edu!bugs (Bug Reports)
Message-Id: <9003081340.AA06728@expo.lcs.mit.edu>
To: bug-trackers@expo.lcs.mit.edu
Subject: XBUG #2689:  bug in R4 cfbbitblt.c
Status: R

(Message /bugs/Mail/inbox:365)
Return-Path: ingr!b11!doyled!doyle@uunet.uu.net
Received: from uunet.uu.net by expo.lcs.mit.edu; Fri, 2 Mar 90 20:57:55 EST
Received: from ingr.UUCP by uunet.uu.net (5.61/1.14) with UUCP 
	id AA18997; Fri, 2 Mar 90 11:55:53 -0500
Message-Id: <9003021655.AA18997@uunet.uu.net>
Subject: bug in R4 cfbbitblt.c
To: xbugs@expo.lcs.mit.edu
Date: Fri, 2 Mar 90 10:01:47 CST
From: Doyle C. Davidson <doyled!doyle@uunet.uu.net>
X-Mailer: Elm [version 2.1 PL1]

### bug number:   2689
### area:         server
### severity:     medium high
### comments:     


			  X Window System Bug Report
			    xbugs@expo.lcs.mit.edu


VERSION:
    R4

CLIENT MACHINE and OPERATING SYSTEM:
    Intergraph 6000 series and System V

DISPLAY TYPE:
    8 plane memory mapped

WINDOW MANAGER:
    twm

AREA:
    server (cfbDoBitblt)

SYNOPSIS:
    There are missing DEALLOCATE_LOCAL calls in cfbDoBitblt()
    for the following variables:
	pptNew1  pboxNew1  pptNew2  pboxNew2

DESCRIPTION:
    See source code for cfbDoBtiblt() in cfbbitblt.c
    The mfb code seems ok.

REPEAT BY:
    Scroll a paritally covered window.  I.e. xterm covered by an xclock.

SAMPLE FIX:
*** /tmp/,RCSt1a01689   Fri Mar  2 09:58:19 1990
--- cfbbitblt.c Fri Mar  2 09:46:26 1990
***************
*** 675,680
            pptSrc++;
        }
      }
  }

  int (*doBitBlt)() = cfbDoBitblt;

--- 675,691 -----
            pptSrc++;
        }
      }
+     /* free up stuff */
+     if (pboxNew2)
+     {
+       DEALLOCATE_LOCAL(pptNew2);
+       DEALLOCATE_LOCAL(pboxNew2);
+     }
+     if (pboxNew1)
+     {
+       DEALLOCATE_LOCAL(pptNew1);
+       DEALLOCATE_LOCAL(pboxNew1);
+     }
  }

  int (*doBitBlt)() = cfbDoBitblt;
=========================
Doyle
-------------------------------
Doyle C. Davidson              
Intergraph Corp.               
Workstation Graphics Standards 
1 Madison Industrial Park      
Huntsville, AL 35894-0001      
(205) 730-2000                 
                               
..!uunet!ingr!b11!doyled!doyle 
--------------------------------



