Subject: bug#24673: 25.1.50; Evaluating '((closure))' aborts Emacs

From: Philipp Stephani <[email-masked]>
Date: Wed, 12 Oct 2016 20:52:12 +0000

Andreas Politz <[email-masked]> schrieb am Mi., 12. Okt. 2016
um 12:28 Uhr:

>
>
> emacs -Q
>
>
>
> M-x ((closure)) RET
>
>
>
> => eval.c:2845: Emacs fatal error: assertion failed: CONSP (fun)
>
>
>
Thanks for reporting, if nobody complains I'll push the attached patch to
emacs-25.
From e8a7ffad370d6bbbf7c7bc29179a7b196cfc3415 Mon Sep 17 00:00:00 2001
From: Philipp Stephani <[email-masked]>
Date: Wed, 12 Oct 2016 22:48:32 +0200
Subject: [PATCH] Fix crash in evaluating functions

See Bug#24673

* src/eval.c (funcall_lambda): Fix crash for bogus functions such
as ((closure)).

* test/automated/eval-tests.el (eval-tests--bug24673): Add test.
---
 src/eval.c                   |  2 +-
 test/automated/eval-tests.el | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 test/automated/eval-tests.el

diff --git a/src/eval.c b/src/eval.c
index fe6460d..aa08cc9 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -2821,7 +2821,7 @@ funcall_lambda (Lisp_Object fun, ptrdiff_t nargs,
       if (EQ (XCAR (fun), Qclosure))
 	{
 	  fun = XCDR (fun);	/* Drop `closure'.  */
-	  lexenv = XCAR (fun);
+	  lexenv = CAR (fun);
 	  CHECK_LIST_CONS (fun, fun);
 	}
       else
diff --git a/test/automated/eval-tests.el b/test/automated/eval-tests.el
new file mode 100644
index 0000000..1455cf3
--- /dev/null
+++ b/test/automated/eval-tests.el
@@ -0,0 +1,35 @@
+;;; eval-tests.el --- unit tests for src/eval.c      -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2016 Free Software Foundation, Inc.
+
+;; Author: Philipp Stephani <[email-masked]>
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Unit tests for src/eval.c.
+
+;;; Code:
+
+(require 'ert)
+
+(ert-deftest eval-tests--bug24673 ()
+  "Checks that Bug#24673 has been fixed."
+  ;; This should not crash.
+  (should-error (eval '((closure)))) :type 'wrong-type-argument)
+
+;;; eval-tests.el ends here
-- 
2.8.0.rc3.226.g39d4020