Karsten Hopp 7d23b9
To: vim_dev@googlegroups.com
Karsten Hopp 7d23b9
Subject: Patch 7.3.1278
Karsten Hopp 7d23b9
Fcc: outbox
Karsten Hopp 7d23b9
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp 7d23b9
Mime-Version: 1.0
Karsten Hopp 7d23b9
Content-Type: text/plain; charset=UTF-8
Karsten Hopp 7d23b9
Content-Transfer-Encoding: 8bit
Karsten Hopp 7d23b9
------------
Karsten Hopp 7d23b9
Karsten Hopp 7d23b9
Patch 7.3.1278
Karsten Hopp 7d23b9
Problem:    When someone sets the screen size to a huge value with "stty" Vim
Karsten Hopp 7d23b9
	    runs out of memory before reducing the size.
Karsten Hopp 7d23b9
Solution:   Limit Rows and Columns in more places.
Karsten Hopp 7d23b9
Files:	    src/gui.c, src/gui_gtk_x11.c, src/option.c, src/os_unix.c,
Karsten Hopp 7d23b9
	    src/proto/term.pro, src/term.c
Karsten Hopp 7d23b9
Karsten Hopp 7d23b9
Karsten Hopp 7d23b9
*** ../vim-7.3.1277/src/gui.c	2013-06-29 15:19:17.000000000 +0200
Karsten Hopp 7d23b9
--- src/gui.c	2013-06-30 17:41:48.000000000 +0200
Karsten Hopp 7d23b9
***************
Karsten Hopp 7d23b9
*** 1620,1625 ****
Karsten Hopp 7d23b9
--- 1620,1626 ----
Karsten Hopp 7d23b9
  	    un_maximize = FALSE;
Karsten Hopp 7d23b9
  #endif
Karsten Hopp 7d23b9
      }
Karsten Hopp 7d23b9
+     limit_screen_size();
Karsten Hopp 7d23b9
      gui.num_cols = Columns;
Karsten Hopp 7d23b9
      gui.num_rows = Rows;
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
*** ../vim-7.3.1277/src/gui_gtk_x11.c	2013-05-21 12:52:00.000000000 +0200
Karsten Hopp 7d23b9
--- src/gui_gtk_x11.c	2013-06-30 17:42:13.000000000 +0200
Karsten Hopp 7d23b9
***************
Karsten Hopp 7d23b9
*** 3698,3703 ****
Karsten Hopp 7d23b9
--- 3698,3704 ----
Karsten Hopp 7d23b9
  		p_window = h - 1;
Karsten Hopp 7d23b9
  	    Rows = h;
Karsten Hopp 7d23b9
  	}
Karsten Hopp 7d23b9
+ 	limit_screen_size();
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
  	pixel_width = (guint)(gui_get_base_width() + Columns * gui.char_width);
Karsten Hopp 7d23b9
  	pixel_height = (guint)(gui_get_base_height() + Rows * gui.char_height);
Karsten Hopp 7d23b9
*** ../vim-7.3.1277/src/option.c	2013-06-29 14:42:21.000000000 +0200
Karsten Hopp 7d23b9
--- src/option.c	2013-06-30 17:45:36.000000000 +0200
Karsten Hopp 7d23b9
***************
Karsten Hopp 7d23b9
*** 8528,8538 ****
Karsten Hopp 7d23b9
  	}
Karsten Hopp 7d23b9
  	Columns = MIN_COLUMNS;
Karsten Hopp 7d23b9
      }
Karsten Hopp 7d23b9
!     /* Limit the values to avoid an overflow in Rows * Columns. */
Karsten Hopp 7d23b9
!     if (Columns > 10000)
Karsten Hopp 7d23b9
! 	Columns = 10000;
Karsten Hopp 7d23b9
!     if (Rows > 1000)
Karsten Hopp 7d23b9
! 	Rows = 1000;
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
  #ifdef DJGPP
Karsten Hopp 7d23b9
      /* avoid a crash by checking for a too large value of 'columns' */
Karsten Hopp 7d23b9
--- 8528,8534 ----
Karsten Hopp 7d23b9
  	}
Karsten Hopp 7d23b9
  	Columns = MIN_COLUMNS;
Karsten Hopp 7d23b9
      }
Karsten Hopp 7d23b9
!     limit_screen_size();
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
  #ifdef DJGPP
Karsten Hopp 7d23b9
      /* avoid a crash by checking for a too large value of 'columns' */
Karsten Hopp 7d23b9
*** ../vim-7.3.1277/src/os_unix.c	2013-06-29 14:16:58.000000000 +0200
Karsten Hopp 7d23b9
--- src/os_unix.c	2013-06-30 17:43:25.000000000 +0200
Karsten Hopp 7d23b9
***************
Karsten Hopp 7d23b9
*** 3777,3782 ****
Karsten Hopp 7d23b9
--- 3777,3783 ----
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
      Rows = rows;
Karsten Hopp 7d23b9
      Columns = columns;
Karsten Hopp 7d23b9
+     limit_screen_size();
Karsten Hopp 7d23b9
      return OK;
Karsten Hopp 7d23b9
  }
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
*** ../vim-7.3.1277/src/proto/term.pro	2013-03-13 19:29:24.000000000 +0100
Karsten Hopp 7d23b9
--- src/proto/term.pro	2013-06-30 17:47:49.000000000 +0200
Karsten Hopp 7d23b9
***************
Karsten Hopp 7d23b9
*** 26,31 ****
Karsten Hopp 7d23b9
--- 26,32 ----
Karsten Hopp 7d23b9
  void ttest __ARGS((int pairs));
Karsten Hopp 7d23b9
  void add_long_to_buf __ARGS((long_u val, char_u *dst));
Karsten Hopp 7d23b9
  void check_shellsize __ARGS((void));
Karsten Hopp 7d23b9
+ void limit_screen_size __ARGS((void));
Karsten Hopp 7d23b9
  void win_new_shellsize __ARGS((void));
Karsten Hopp 7d23b9
  void shell_resized __ARGS((void));
Karsten Hopp 7d23b9
  void shell_resized_check __ARGS((void));
Karsten Hopp 7d23b9
*** ../vim-7.3.1277/src/term.c	2013-05-15 14:22:36.000000000 +0200
Karsten Hopp 7d23b9
--- src/term.c	2013-06-30 17:47:34.000000000 +0200
Karsten Hopp 7d23b9
***************
Karsten Hopp 7d23b9
*** 2962,2976 ****
Karsten Hopp 7d23b9
  #endif
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
  /*
Karsten Hopp 7d23b9
!  * Check if the new shell size is valid, correct it if it's too small.
Karsten Hopp 7d23b9
   */
Karsten Hopp 7d23b9
      void
Karsten Hopp 7d23b9
  check_shellsize()
Karsten Hopp 7d23b9
  {
Karsten Hopp 7d23b9
-     if (Columns < MIN_COLUMNS)
Karsten Hopp 7d23b9
- 	Columns = MIN_COLUMNS;
Karsten Hopp 7d23b9
      if (Rows < min_rows())	/* need room for one window and command line */
Karsten Hopp 7d23b9
  	Rows = min_rows();
Karsten Hopp 7d23b9
  }
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
  /*
Karsten Hopp 7d23b9
--- 2962,2990 ----
Karsten Hopp 7d23b9
  #endif
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
  /*
Karsten Hopp 7d23b9
!  * Check if the new shell size is valid, correct it if it's too small or way
Karsten Hopp 7d23b9
!  * too big.
Karsten Hopp 7d23b9
   */
Karsten Hopp 7d23b9
      void
Karsten Hopp 7d23b9
  check_shellsize()
Karsten Hopp 7d23b9
  {
Karsten Hopp 7d23b9
      if (Rows < min_rows())	/* need room for one window and command line */
Karsten Hopp 7d23b9
  	Rows = min_rows();
Karsten Hopp 7d23b9
+     limit_screen_size();
Karsten Hopp 7d23b9
+ }
Karsten Hopp 7d23b9
+ 
Karsten Hopp 7d23b9
+ /*
Karsten Hopp 7d23b9
+  * Limit Rows and Columns to avoid an overflow in Rows * Columns.
Karsten Hopp 7d23b9
+  */
Karsten Hopp 7d23b9
+     void
Karsten Hopp 7d23b9
+ limit_screen_size()
Karsten Hopp 7d23b9
+ {
Karsten Hopp 7d23b9
+     if (Columns < MIN_COLUMNS)
Karsten Hopp 7d23b9
+ 	Columns = MIN_COLUMNS;
Karsten Hopp 7d23b9
+     else if (Columns > 10000)
Karsten Hopp 7d23b9
+ 	Columns = 10000;
Karsten Hopp 7d23b9
+     if (Rows > 1000)
Karsten Hopp 7d23b9
+ 	Rows = 1000;
Karsten Hopp 7d23b9
  }
Karsten Hopp 7d23b9
  
Karsten Hopp 7d23b9
  /*
Karsten Hopp 7d23b9
*** ../vim-7.3.1277/src/version.c	2013-06-30 17:23:46.000000000 +0200
Karsten Hopp 7d23b9
--- src/version.c	2013-06-30 17:50:34.000000000 +0200
Karsten Hopp 7d23b9
***************
Karsten Hopp 7d23b9
*** 730,731 ****
Karsten Hopp 7d23b9
--- 730,733 ----
Karsten Hopp 7d23b9
  {   /* Add new patch number below this line */
Karsten Hopp 7d23b9
+ /**/
Karsten Hopp 7d23b9
+     1278,
Karsten Hopp 7d23b9
  /**/
Karsten Hopp 7d23b9
Karsten Hopp 7d23b9
-- 
Karsten Hopp 7d23b9
ARTHUR:  Be quiet!
Karsten Hopp 7d23b9
DENNIS:  --but by a two-thirds majority in the case of more--
Karsten Hopp 7d23b9
ARTHUR:  Be quiet!  I order you to be quiet!
Karsten Hopp 7d23b9
WOMAN:   Order, eh -- who does he think he is?
Karsten Hopp 7d23b9
ARTHUR:  I am your king!
Karsten Hopp 7d23b9
                                  The Quest for the Holy Grail (Monty Python)
Karsten Hopp 7d23b9
Karsten Hopp 7d23b9
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp 7d23b9
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp 7d23b9
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp 7d23b9
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///