From: Mattias Engdegård Date: Wed, 8 Apr 2020 15:13:39 +0000 (+0200) Subject: Don't crash with invalid argument in check-coding-systems-region X-Git-Tag: emacs-28.0.90~7624 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=786887cf439450ce7d8d6fbe624e8c434e50d469;p=emacs.git Don't crash with invalid argument in check-coding-systems-region * src/coding.c (Fcheck_coding_systems_region): Don't crash if the third arg contains something that isn't a coding system. * test/src/coding-tests.el (coding-check-coding-systems-region): New test. --- diff --git a/src/coding.c b/src/coding.c index c24c70c0899..ffcb9cf0a1a 100644 --- a/src/coding.c +++ b/src/coding.c @@ -9302,7 +9302,10 @@ is nil. */) for (tail = coding_system_list; CONSP (tail); tail = XCDR (tail)) { elt = XCAR (tail); - attrs = AREF (CODING_SYSTEM_SPEC (elt), 0); + Lisp_Object spec = CODING_SYSTEM_SPEC (elt); + if (!VECTORP (spec)) + xsignal1 (Qcoding_system_error, elt); + attrs = AREF (spec, 0); ASET (attrs, coding_attr_trans_tbl, get_translation_table (attrs, 1, NULL)); list = Fcons (list2 (elt, attrs), list); diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el index 83a06b8179e..8d92bcdcd1a 100644 --- a/test/src/coding-tests.el +++ b/test/src/coding-tests.el @@ -411,6 +411,14 @@ (should (eq (decode-coding-string s coding t) s)) (should (eq (encode-coding-string s coding t) s)))))) +(ert-deftest coding-check-coding-systems-region () + (should (equal (check-coding-systems-region "aÃ¥" nil '(utf-8)) + nil)) + (should (equal (check-coding-systems-region "aÃ¥bγc" nil + '(utf-8 iso-latin-1 us-ascii)) + '((iso-latin-1 3) (us-ascii 1 3)))) + (should-error (check-coding-systems-region "Ã¥" nil '(bad-coding-system)))) + ;; Local Variables: ;; byte-compile-warnings: (not obsolete) ;; End: