]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid undefined behavior in 'defvar' (Bug#31072)
authorPhilipp Stephani <phst@google.com>
Mon, 16 Apr 2018 06:45:27 +0000 (23:45 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 16 Apr 2018 06:50:06 +0000 (23:50 -0700)
* src/eval.c (Fdefvar): Check that first argument is a symbol.
* test/src/eval-tests.el (defvar/bug31072): New unit test.

src/eval.c
test/src/eval-tests.el

index a6e1d86c4abd12e5b8a9982c8126f207f3f15865..90d8c3351855de7d9f83caddc407850de4126dba 100644 (file)
@@ -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))))
index 59da6b7cc304af43ab25fd05fb62fdbd2af4fa1e..319dd91c86a9a4f2f7eb7d35b632e4973ca63651 100644 (file)
@@ -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