From 9f2d21ca536ea7ca1da98e7bd57ae535ab394997 Mon Sep 17 00:00:00 2001 From: Philipp Stephani Date: Sun, 15 Apr 2018 23:45:27 -0700 Subject: [PATCH] Avoid undefined behavior in 'defvar' (Bug#31072) * src/eval.c (Fdefvar): Check that first argument is a symbol. * test/src/eval-tests.el (defvar/bug31072): New unit test. --- src/eval.c | 2 ++ test/src/eval-tests.el | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/eval.c b/src/eval.c index a6e1d86c4ab..90d8c335185 100644 --- a/src/eval.c +++ b/src/eval.c @@ -737,6 +737,8 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) sym = XCAR (args); tail = XCDR (args); + CHECK_SYMBOL (sym); + if (!NILP (tail)) { if (!NILP (XCDR (tail)) && !NILP (XCDR (XCDR (tail)))) diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el index 59da6b7cc30..319dd91c86a 100644 --- a/test/src/eval-tests.el +++ b/test/src/eval-tests.el @@ -113,4 +113,8 @@ crash/abort/malloc assert failure on the next test." (signal-hook-function #'ignore)) (should-error (eval-tests--exceed-specbind-limit)))) +(ert-deftest defvar/bug31072 () + "Check that Bug#31072 is fixed." + (should-error (eval '(defvar 1) t) :type 'wrong-type-argument)) + ;;; eval-tests.el ends here -- 2.39.5