From 786887cf439450ce7d8d6fbe624e8c434e50d469 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mattias=20Engdeg=C3=A5rd?= Date: Wed, 8 Apr 2020 17:13:39 +0200 Subject: [PATCH] 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. --- src/coding.c | 5 ++++- test/src/coding-tests.el | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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: -- 2.39.5