From 40ae02ff50a8f05660a7f9f234320875b6358c9d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 30 Oct 2019 14:17:40 -0700 Subject: Fix fileio.c infloops on circular lists Fix infinite loops in fileio.c when a circular list is the value of after_insert_file_functions, buffer-auto-save-file-format, buffer-file-format, or write-region-annotate-functions. * src/fileio.c (Finsert_file_contents, build_annotations): Use FOR_EACH_TAIL to avoid infloop on circular lists. (build_annotations): Use an EMACS_INT, not an int, to count nesting level. * test/src/fileio-tests.el: (fileio-tests--circular-after-insert-file-functions): New test. --- test/src/fileio-tests.el | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'test/src') diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el index 98d3d6be763..2225897af8c 100644 --- a/test/src/fileio-tests.el +++ b/test/src/fileio-tests.el @@ -147,3 +147,12 @@ Also check that an encoding error can appear in a symlink." (should (file-name-absolute-p (concat "~" user-login-name suffix)))) (unless (user-full-name "nosuchuser") (should (not (file-name-absolute-p (concat "~nosuchuser" suffix))))))) + +(ert-deftest fileio-tests--circular-after-insert-file-functions () + "Test after-insert-file-functions as a circular list." + (let ((f (make-temp-file "fileio")) + (after-insert-file-functions (list 'identity))) + (setcdr after-insert-file-functions after-insert-file-functions) + (write-region "hello\n" nil f nil 'silent) + (should-error (insert-file-contents f) :type 'circular-list) + (delete-file f))) -- cgit v1.2.1