bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#21602: 25.0.50; coding system seg fault


From: Eli Zaretskii
Subject: bug#21602: 25.0.50; coding system seg fault
Date: Sat, 03 Oct 2015 13:48:38 +0300

> From: Richard Stallman <rms@gnu.org>
> CC: 21602@debbugs.gnu.org
> Date: Fri, 02 Oct 2015 21:37:48 -0400
> 
> I can reproduce the failure in emacs -Q with the code below.  The code
> in my-send-1 is responsible for passing specifying the coding system,
> but even if that value is wrong, write-region should not crash.

Thanks.  For the record, here's a simpler way of triggering the same
crash:

  emacs -Q

Type in *scratch*:

  (let ((coding-system-for-write (intern "\"us-ascii\"")))
    (write-region 1 10 "/tmp/SEGV"))

Evaluate this sexp, and you get the same segfault.

The problem here is that we don't check the validity of the
coding-system the user forced on us, until it's too late.

I found a couple more cases of missing validation like this one, and
fixed them all in commit 658f2c4.  The diffs are below.

diff --git a/src/fileio.c b/src/fileio.c
index e4b255a..65aaf57 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;






reply via email to

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