From: Eli Zaretskii Date: Sun, 15 Dec 2013 18:37:48 +0000 (+0200) Subject: Fix bug #16152 with crashes in process-send-eof on MS-Windows. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~398 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1014b1dc34ed9717c48a089f45423235f09b1101;p=emacs.git Fix bug #16152 with crashes in process-send-eof on MS-Windows. src/process.c (Fprocess_send_eof): Don't crash if someone tries to open a pty on MS-Windows. --- diff --git a/src/ChangeLog b/src/ChangeLog index da3b78e0f25..d2ea1502a98 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2013-12-15 Eli Zaretskii + * process.c (Fprocess_send_eof): Don't crash if someone tries to + open a pty on MS-Windows. (Bug#16152) + * emacs.c (decode_env_path): Fix bogus comparison against emacs_dir. Reported by Juanma Barranquero . diff --git a/src/process.c b/src/process.c index 7050bf9822e..dac4b14dcea 100644 --- a/src/process.c +++ b/src/process.c @@ -6032,13 +6032,16 @@ process has been transmitted to the serial port. */) (Lisp_Object process) { Lisp_Object proc; - struct coding_system *coding; + struct coding_system *coding = NULL; + int outfd; if (DATAGRAM_CONN_P (process)) return process; proc = get_process (process); - coding = proc_encode_coding_system[XPROCESS (proc)->outfd]; + outfd = XPROCESS (proc)->outfd; + if (outfd >= 0) + coding = proc_encode_coding_system[outfd]; /* Make sure the process is really alive. */ if (XPROCESS (proc)->raw_status_new) @@ -6046,7 +6049,7 @@ process has been transmitted to the serial port. */) if (! EQ (XPROCESS (proc)->status, Qrun)) error ("Process %s not running", SDATA (XPROCESS (proc)->name)); - if (CODING_REQUIRE_FLUSHING (coding)) + if (coding && CODING_REQUIRE_FLUSHING (coding)) { coding->mode |= CODING_MODE_LAST_BLOCK; send_process (proc, "", 0, Qnil); @@ -6064,7 +6067,8 @@ process has been transmitted to the serial port. */) } else { - int old_outfd = XPROCESS (proc)->outfd; + struct Lisp_Process *p = XPROCESS (proc); + int old_outfd = p->outfd; int new_outfd; #ifdef HAVE_SHUTDOWN @@ -6072,24 +6076,30 @@ process has been transmitted to the serial port. */) for communication with the subprocess, call shutdown to cause EOF. (In some old system, shutdown to socketpair doesn't work. Then we just can't win.) */ - if (EQ (XPROCESS (proc)->type, Qnetwork) - || XPROCESS (proc)->infd == old_outfd) + if (EQ (p->type, Qnetwork) + || p->infd == old_outfd) shutdown (old_outfd, 1); #endif - close_process_fd (&XPROCESS (proc)->open_fd[WRITE_TO_SUBPROCESS]); + close_process_fd (&p->open_fd[WRITE_TO_SUBPROCESS]); new_outfd = emacs_open (NULL_DEVICE, O_WRONLY, 0); if (new_outfd < 0) report_file_error ("Opening null device", Qnil); - XPROCESS (proc)->open_fd[WRITE_TO_SUBPROCESS] = new_outfd; - XPROCESS (proc)->outfd = new_outfd; + p->open_fd[WRITE_TO_SUBPROCESS] = new_outfd; + p->outfd = new_outfd; if (!proc_encode_coding_system[new_outfd]) proc_encode_coding_system[new_outfd] = xmalloc (sizeof (struct coding_system)); - *proc_encode_coding_system[new_outfd] - = *proc_encode_coding_system[old_outfd]; - memset (proc_encode_coding_system[old_outfd], 0, - sizeof (struct coding_system)); + if (old_outfd >= 0) + { + *proc_encode_coding_system[new_outfd] + = *proc_encode_coding_system[old_outfd]; + memset (proc_encode_coding_system[old_outfd], 0, + sizeof (struct coding_system)); + } + else + setup_coding_system (p->encode_coding_system, + proc_encode_coding_system[new_outfd]); } return process; }