emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 786887c 2/4: Don't crash with invalid argument in check-coding-sy


From: Mattias Engdegård
Subject: master 786887c 2/4: Don't crash with invalid argument in check-coding-systems-region
Date: Thu, 9 Apr 2020 07:04:09 -0400 (EDT)

branch: master
commit 786887cf439450ce7d8d6fbe624e8c434e50d469
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    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 c24c70c..ffcb9cf 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 83a06b8..8d92bcd 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:



reply via email to

[Prev in Thread] Current Thread [Next in Thread]