emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117485: * process.c: Add sanity checks for file des


From: Paul Eggert
Subject: [Emacs-diffs] trunk r117485: * process.c: Add sanity checks for file descriptors.
Date: Tue, 08 Jul 2014 06:24:12 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117485
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/17844
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Mon 2014-07-07 23:24:07 -0700
message:
  * process.c: Add sanity checks for file descriptors.
  
  (wait_reading_process_output, Fprocess_filter_multibyte_p):
  Check that infd is nonnegative before using it as an fd.
  (read_and_dispose_of_process_output, Fprocess_send_eof):
  Likewise, for outfd.
  (wait_reading_process_output): Omit unnecessary check of infd.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/process.c                  process.c-20091113204419-o5vbwnq5f7feedwu-462
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-07-07 23:33:05 +0000
+++ b/src/ChangeLog     2014-07-08 06:24:07 +0000
@@ -1,3 +1,12 @@
+2014-07-08  Paul Eggert  <address@hidden>
+
+       * process.c: Add sanity checks for file descriptors (Bug#17844).
+       (wait_reading_process_output, Fprocess_filter_multibyte_p):
+       Check that infd is nonnegative before using it as an fd.
+       (read_and_dispose_of_process_output, Fprocess_send_eof):
+       Likewise, for outfd.
+       (wait_reading_process_output): Omit unnecessary check of infd.
+
 2014-07-07  Paul Eggert  <address@hidden>
 
        Minor fixups related to usage of the 'long' type.

=== modified file 'src/process.c'
--- a/src/process.c     2014-06-24 08:10:48 +0000
+++ b/src/process.c     2014-07-08 06:24:07 +0000
@@ -4462,6 +4462,7 @@
       if (wait_proc && wait_proc->raw_status_new)
        update_status (wait_proc);
       if (wait_proc
+         && wait_proc->infd >= 0
          && ! EQ (wait_proc->status, Qrun)
          && ! EQ (wait_proc->status, Qconnect))
        {
@@ -4471,7 +4472,7 @@
          XSETPROCESS (proc, wait_proc);
 
          /* Read data from the process, until we exhaust it.  */
-         while (wait_proc->infd >= 0)
+         while (true)
            {
              int nread = read_process_output (proc, wait_proc->infd);
              if (nread < 0)
@@ -4642,6 +4643,7 @@
                          > 0))
                    {
                      nfds = 1;
+                     eassert (0 <= wait_proc->infd);
                      /* Set to Available.  */
                      FD_SET (wait_proc->infd, &Available);
                    }
@@ -4909,7 +4911,8 @@
                     status_notify to do it later, it will read input
                     from the process before calling the sentinel.  */
                  exec_sentinel (proc, build_string ("open\n"));
-                 if (!EQ (p->filter, Qt) && !EQ (p->command, Qt))
+                 if (0 <= p->infd && !EQ (p->filter, Qt)
+                     && !EQ (p->command, Qt))
                    {
                      FD_SET (p->infd, &input_wait_mask);
                      FD_SET (p->infd, &non_keyboard_wait_mask);
@@ -5131,7 +5134,7 @@
         proc_encode_coding_system[p->outfd] surely points to a
         valid memory because p->outfd will be changed once EOF is
         sent to the process.  */
-      if (NILP (p->encode_coding_system)
+      if (NILP (p->encode_coding_system) && p->outfd
          && proc_encode_coding_system[p->outfd])
        {
          pset_encode_coding_system
@@ -6071,8 +6074,8 @@
         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 (p->type, Qnetwork)
-         || p->infd == old_outfd)
+      if (0 <= old_outfd
+         && (EQ (p->type, Qnetwork) || p->infd == old_outfd))
        shutdown (old_outfd, 1);
 #endif
       close_process_fd (&p->open_fd[WRITE_TO_SUBPROCESS]);
@@ -6546,6 +6549,8 @@
 
   CHECK_PROCESS (process);
   p = XPROCESS (process);
+  if (p->infd < 0)
+    return Qnil;
   coding = proc_decode_coding_system[p->infd];
   return (CODING_FOR_UNIBYTE (coding) ? Qnil : Qt);
 }


reply via email to

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