emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r114012: Fix unlikely core dump in init_tty, and sim


From: Paul Eggert
Subject: [Emacs-diffs] trunk r114012: Fix unlikely core dump in init_tty, and simplify terminfo case.
Date: Mon, 26 Aug 2013 18:10:34 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 114012
revision-id: address@hidden
parent: address@hidden
author: Paul Eggert  <address@hidden>
committer: Paul Eggert <address@hidden>
branch nick: trunk
timestamp: Mon 2013-08-26 11:10:30 -0700
message:
  Fix unlikely core dump in init_tty, and simplify terminfo case.
  
  * term.c (init_tty) [TERMINFO]: Fix check for buffer overrun.
  The old version incorrectly dumped core if malloc returned a
  buffer containing only non-NUL bytes.
  (init_tty): Do not allocate or free termcap buffers; the
  struct does that for us now.
  * termchar.h (TERMCAP_BUFFER_SIZE) [!TERMINFO]: New constant.
  (struct tty_display_info): Define members termcap_term_buffer and
  termcap_strings_buffer only if !TERMINFO, since terminfo doesn't
  use them.  Allocate them directly in struct rather than indirectly
  via a pointer, to simplify init_tty.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/term.c                     term.c-20091113204419-o5vbwnq5f7feedwu-220
  src/termchar.h                 termchar.h-20091113204419-o5vbwnq5f7feedwu-440
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-08-26 17:31:00 +0000
+++ b/src/ChangeLog     2013-08-26 18:10:30 +0000
@@ -1,5 +1,17 @@
 2013-08-26  Paul Eggert  <address@hidden>
 
+       Fix unlikely core dump in init_tty, and simplify terminfo case.
+       * term.c (init_tty) [TERMINFO]: Fix check for buffer overrun.
+       The old version incorrectly dumped core if malloc returned a
+       buffer containing only non-NUL bytes.
+       (init_tty): Do not allocate or free termcap buffers; the
+       struct does that for us now.
+       * termchar.h (TERMCAP_BUFFER_SIZE) [!TERMINFO]: New constant.
+       (struct tty_display_info): Define members termcap_term_buffer and
+       termcap_strings_buffer only if !TERMINFO, since terminfo doesn't
+       use them.  Allocate them directly in struct rather than indirectly
+       via a pointer, to simplify init_tty.
+
        * frame.c (check_minibuf_window): Initialize 'window' properly,
        so that Emacs reliably aborts later if 'window' is not initialized.
 

=== modified file 'src/term.c'
--- a/src/term.c        2013-08-15 05:23:40 +0000
+++ b/src/term.c        2013-08-26 18:10:30 +0000
@@ -2934,9 +2934,12 @@
 struct terminal *
 init_tty (const char *name, const char *terminal_type, bool must_succeed)
 {
-  char *area = NULL;
+#ifdef TERMINFO
+  char **address = 0;
+#else
+  char *area;
   char **address = &area;
-  int buffer_size = 4096;
+#endif
   int status;
   struct tty_display_info *tty = NULL;
   struct terminal *terminal = NULL;
@@ -3024,12 +3027,16 @@
 
   Wcm_clear (tty);
 
-  tty->termcap_term_buffer = xmalloc (buffer_size);
-
   /* On some systems, tgetent tries to access the controlling
      terminal.  */
   block_tty_out_signal ();
+#ifdef TERMINFO
+  status = tgetent (0, terminal_type);
+#else
   status = tgetent (tty->termcap_term_buffer, terminal_type);
+  if (tty->termcap_term_buffer[TERMCAP_BUFFER_SIZE - 1])
+    emacs_abort ();
+#endif
   unblock_tty_out_signal ();
 
   if (status < 0)
@@ -3061,11 +3068,8 @@
     }
 
 #ifndef TERMINFO
-  if (strlen (tty->termcap_term_buffer) >= buffer_size)
-    emacs_abort ();
-  buffer_size = strlen (tty->termcap_term_buffer);
+  area = tty->termcap_strings_buffer;
 #endif
-  tty->termcap_strings_buffer = area = xmalloc (buffer_size);
   tty->TS_ins_line = tgetstr ("al", address);
   tty->TS_ins_multi_lines = tgetstr ("AL", address);
   tty->TS_bell = tgetstr ("bl", address);
@@ -3481,9 +3485,6 @@
 
   xfree (tty->old_tty);
   xfree (tty->Wcm);
-  xfree (tty->termcap_strings_buffer);
-  xfree (tty->termcap_term_buffer);
-
   xfree (tty);
 }
 

=== modified file 'src/termchar.h'
--- a/src/termchar.h    2013-01-02 16:13:04 +0000
+++ b/src/termchar.h    2013-08-26 18:10:30 +0000
@@ -28,6 +28,10 @@
   /* There is nothing else here at the moment... */
 };
 
+#ifndef TERMINFO
+enum { TERMCAP_BUFFER_SIZE = 4096 };
+#endif
+
 /* Parameters that are shared between frames on the same tty device. */
 
 struct tty_display_info
@@ -72,14 +76,15 @@
      mouse-face.  */
   Mouse_HLInfo mouse_highlight;
 
+#ifndef TERMINFO
   /* Buffer used internally by termcap (see tgetent in the Termcap
-     manual).  Only init_tty and delete_tty should change this.  */
-  char *termcap_term_buffer;
+     manual).  Only init_tty should use this.  */
+  char termcap_term_buffer[TERMCAP_BUFFER_SIZE];
 
   /* Buffer storing terminal description strings (see tgetstr in the
-     Termcap manual).  Only init_tty and delete_tty should change
-     this.  */
-  char *termcap_strings_buffer;
+     Termcap manual).  Only init_tty should use this.  */
+  char termcap_strings_buffer[TERMCAP_BUFFER_SIZE];
+#endif
 
   /* Strings, numbers and flags taken from the termcap entry.  */
 


reply via email to

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