From 658f2c450d17357d8c09a07ca92c2ca980c3c797 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 3 Oct 2015 13:44:44 +0300 Subject: [PATCH] Avoid crashes due to invalid coding-system * src/fileio.c (choose_write_coding_system) (Finsert_file_contents): Check validity of coding-system-for-write and coding-system-for-read bound by the caller. (Bug#21602) --- src/fileio.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fileio.c b/src/fileio.c index e4b255a53ac..65aaf572fd7 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -3470,7 +3470,10 @@ by calling `format-decode', which see. */) mtime = time_error_value (save_errno); st.st_size = -1; if (!NILP (Vcoding_system_for_read)) - Fset (Qbuffer_file_coding_system, Vcoding_system_for_read); + { + CHECK_CODING_SYSTEM (Vcoding_system_for_read); + Fset (Qbuffer_file_coding_system, Vcoding_system_for_read); + } goto notfound; } @@ -4526,6 +4529,7 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file else if (!NILP (Vcoding_system_for_write)) { val = Vcoding_system_for_write; + CHECK_CODING_SYSTEM (val); if (coding_system_require_warning && !NILP (Ffboundp (Vselect_safe_coding_system_function))) /* Confirm that VAL can surely encode the current region. */ @@ -4574,6 +4578,9 @@ choose_write_coding_system (Lisp_Object start, Lisp_Object end, Lisp_Object file using_default_coding = 1; } + if (!NILP (val)) + CHECK_CODING_SYSTEM (val); + if (! NILP (val) && ! force_raw_text) { Lisp_Object spec, attrs; -- 2.39.2