From: Philipp Stephani Date: Mon, 16 Apr 2018 06:45:27 +0000 (-0700) Subject: Avoid undefined behavior in 'defvar' (Bug#31072) X-Git-Tag: emacs-27.0.90~5169 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9f2d21ca536ea7ca1da98e7bd57ae535ab394997;p=emacs.git 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. --- 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