Subject: 26.3; ERC: Fix ERC's IBuffer format "crash" on killed server buffer

From: Olivier Certner <[email-masked]>
Date: Thu, 22 Oct 2020 23:50:27 +0200

Applies to 26.3, but also to all more recent versions as well.

Bug trigger:
1. Load ERC (e.g., open some IRC connection).
2. Open some channel or query, to have another ERC buffer.
3. Quit the server.
4. Make sure to kill the server buffer, if still there.
5. Launch ibuffer (e.g., type "M-x ibuffer"). Display stops mid-line on a line 
listing some ERC buffer linked to the quit server. Further buffer updates 
(typing 'g') trigger a crash for another reason (another fix to follow-up).

Root cause:
The erc-ibuffer's server column code will return nil in this case, since
the buffer associated to its process has been killed, making the server
information inacessible, and this is not tested properly.

Patch:
Attached.

-- 
Olivier Certner

>From e10325a729d39b32dcf83de17a7f19e5152ec496 Mon Sep 17 00:00:00 2001
From: Olivier Certner <[email-masked]>
Date: Thu, 22 Oct 2020 23:14:22 +0200
Subject: [PATCH] ERC: Fix ERC's IBuffer format "crash" on killed server buffer

* lisp/erc/erc-ibuffer.el (erc-server-name): Fix a crash when
displaying (or updating) an IBuffer buffer using ERC's first IBuffer
format.  This happens when one ERC buffer has its associated server
buffer killed, e.g., voluntarily or automatically after server
disconnection when `erc-kill-server-buffer-on-quit' is set to t.  The
culprit is the "Server" column, which returns nil in this case.
Display "(closed)" instead.
---
 ChangeLog.3             | 13 +++++++++++++
 lisp/erc/erc-ibuffer.el | 12 ++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/ChangeLog.3 b/ChangeLog.3
index ec2d3f8d46..65c846a307 100644
--- a/ChangeLog.3
+++ b/ChangeLog.3
@@ -1,3 +1,16 @@
+2020-10-22  Olivier Certner  <[email-masked]>
+
+	ERC: Fix ERC's IBuffer format "crash" on killed server buffer
+
+	* lisp/erc/erc-ibuffer.el (erc-server-name): Fix a crash when
+	displaying (or updating) an IBuffer buffer using ERC's first
+	IBuffer format.  This happens when one ERC buffer has its
+	associated server buffer killed, e.g., voluntarily or
+	automatically after server disconnection when
+	`erc-kill-server-buffer-on-quit' is set to t.  The culprit is the
+	"Server" column, which returns nil in this case.  Display
+	"(closed)" instead.
+
 2020-08-03  Phil Sainty  <[email-masked]>
 
 	lisp/so-long.el: Improve support for major mode hooks
diff --git a/lisp/erc/erc-ibuffer.el b/lisp/erc/erc-ibuffer.el
index 7aee7705ff..556a25e3e7 100644
--- a/lisp/erc/erc-ibuffer.el
+++ b/lisp/erc/erc-ibuffer.el
@@ -92,10 +92,14 @@
     " "))
 
 (define-ibuffer-column erc-server-name (:name "Server")
-  (if (and erc-server-process (processp erc-server-process))
-      (with-current-buffer (process-buffer erc-server-process)
-	(or erc-server-announced-name erc-session-server))
-    ""))
+  (or
+   (when (and erc-server-process (processp erc-server-process))
+     (let ((buffer (process-buffer erc-server-process)))
+       (if (buffer-live-p buffer)
+         (with-current-buffer buffer
+           (or erc-server-announced-name erc-session-server))
+         "(closed)")))
+   ""))
 
 (define-ibuffer-column erc-target (:name "Target")
   (if (eq major-mode 'erc-mode)
-- 
2.24.1