Subject: bug#56372: 29.0.50; [PATCH] Avoid BadMatch X11 error

From: Po Lu <[email-masked]>
Date: Mon, 04 Jul 2022 18:10:00 +0800

dick <[email-masked]> writes:

>>>From 5d2442a836a5641f8f1c2b4a844fe510a77bd8c5 Mon Sep 17 00:00:00 2001
> From: dickmao <[email-masked]>
> Date: Mon, 4 Jul 2022 00:47:34 -0400
> Subject: [PATCH] Avoid segfault
>
> * src/xterm.c (x_connection_closed): Avoid segfault.
> ---
>  src/xterm.c | 23 ++++++++++++-----------
>  1 file changed, 12 insertions(+), 11 deletions(-)
>
> diff --git a/src/xterm.c b/src/xterm.c
> index c5acb450837..464887da975 100644
> --- a/src/xterm.c
> +++ b/src/xterm.c
> @@ -23518,17 +23518,18 @@ x_connection_closed (Display *dpy, const char *error_message, bool ioerror)
>  
>  	  fprintf (stderr, "X error handlers currently installed:\n");
>  
> -	  for (failable = dpyinfo->failable_requests;
> -	       failable < dpyinfo->next_failable_request;
> -	       ++failable)
> -	    {
> -	      if (failable->end)
> -		fprintf (stderr, "Ignoring errors between %lu to %lu\n",
> -			 failable->start, failable->end);
> -	      else
> -		fprintf (stderr, "Ignoring errors from %lu onwards\n",
> -			 failable->start);
> -	    }
> +	  if (dpyinfo)
> +	    for (failable = dpyinfo->failable_requests;
> +		 failable < dpyinfo->next_failable_request;
> +		 ++failable)
> +	      {
> +		if (failable->end)
> +		  fprintf (stderr, "Ignoring errors between %lu to %lu\n",
> +			   failable->start, failable->end);
> +		else
> +		  fprintf (stderr, "Ignoring errors from %lu onwards\n",
> +			   failable->start);
> +	      }
>  
>  	  for (stack = x_error_message; stack; stack = stack->prev)
>  	    fprintf (stderr, "Trapping errors from %lu\n",

That piece of code is already inside "if (dpyinfo)" -- in fact, your
patch misses a use-after-free, which has already been fixed on master.