aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorPaul Eggert2017-08-06 16:57:08 -0700
committerPaul Eggert2017-08-06 16:58:35 -0700
commit93511e94735de5862880f5ea9bf12705c1440363 (patch)
tree8c02753b243688359639e31ed215bc25a19813af /test/src
parent8a406d1185b6c87f6647c141a1cc06786cd9480d (diff)
downloademacs-93511e94735de5862880f5ea9bf12705c1440363.tar.gz
emacs-93511e94735de5862880f5ea9bf12705c1440363.zip
Fix some crashes on self-modifying Elisp code
Prompted by a problem report by Alex in: http://lists.gnu.org/archive/html/emacs-devel/2017-08/msg00143.html * src/eval.c (For, Fprogn, Fsetq, FletX, eval_sub): Compute XCDR (x) near XCAR (x); although this doesn't fix any bugs, it is likely to run a bit faster with typical hardware caches. (Fif): Use Fcdr instead of XCDR, to avoid crashing on self-modifying S-expressions. (Fsetq, Flet, eval_sub): Count the number of arguments as we go instead of trusting an Flength prepass, to avoid problems when the code is self-modifying. (Fquote, Ffunction, Fdefvar, Fdefconst): Prefer !NILP to CONSP where either will do. This is mostly to document the fact that the value must be a proper list. It's also a tiny bit faster on typical machines nowadays. (Fdefconst, FletX): Prefer XCAR+XCDR to Fcar+Fcdr when either will do. (eval_sub): Check that the args are a list as opposed to some other object that has a length. This prevents e.g. (if . "string") from making Emacs dump core in some cases. * test/src/eval-tests.el (eval-tests--if-dot-string) (eval-tests--let-with-circular-defs, eval-tests--mutating-cond): New tests.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/eval-tests.el20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/src/eval-tests.el b/test/src/eval-tests.el
index 03f408716b1..b98de0aa65e 100644
--- a/test/src/eval-tests.el
+++ b/test/src/eval-tests.el
@@ -59,4 +59,24 @@ Bug#24912 and Bug#24913."
59 (should-error (,form ,arg) :type 'wrong-type-argument)) 59 (should-error (,form ,arg) :type 'wrong-type-argument))
60 t))) 60 t)))
61 61
62(ert-deftest eval-tests--if-dot-string ()
63 "Check that Emacs rejects (if . \"string\")."
64 (should-error (eval '(if . "abc")) :type 'wrong-type-argument)
65 (let ((if-tail (list '(setcdr if-tail "abc") t)))
66 (should-error (eval (cons 'if if-tail))))
67 (let ((if-tail (list '(progn (setcdr if-tail "abc") nil) t)))
68 (should-error (eval (cons 'if if-tail)))))
69
70(ert-deftest eval-tests--let-with-circular-defs ()
71 "Check that Emacs reports an error for (let VARS ...) when VARS is circular."
72 (let ((vars (list 'v)))
73 (setcdr vars vars)
74 (dolist (let-sym '(let let*))
75 (should-error (eval (list let-sym vars))))))
76
77(ert-deftest eval-tests--mutating-cond ()
78 "Check that Emacs doesn't crash on a cond clause that mutates during eval."
79 (let ((clauses (list '((progn (setcdr clauses "ouch") nil)))))
80 (should-error (eval (cons 'cond clauses)))))
81
62;;; eval-tests.el ends here 82;;; eval-tests.el ends here