[PATCH] Forbid creation of zero-height canvas

Michael Spang <[email protected]>
Newsgroups gmane.comp.gnu.screen.user
Message-ID <[email protected]>
The code is not prepared to handle a canvas with no lines. One way to
segfault screen with a 0-line canvas is:

  - Start screen
  - Enable caption with ":caption always"
  - Run vim
  - Resize the current terminal to one line high
  - Resize the current terminal to multiple lines high
  - Quit vim

If the window is too small then don't expect this to render ok,
but it does prevent screen from crashing.
---
 src/resize.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/resize.c b/src/resize.c
index 0e491eb..0a911db 100644
--- a/src/resize.c
+++ b/src/resize.c
@@ -153,13 +153,20 @@ int change_fore;
   struct win *p;
   struct canvas *cv;
   int wwi;
+  int minhe;
 
   debug2("ChangeScreenSize from (%d,%d) ", D_width, D_height);
   debug3("to (%d,%d) (change_fore: %d)\n",wi, he, change_fore);
 
   cv = &D_canvas;
+  minhe = 1 + ((cv->c_slperp && cv->c_slperp->c_slnext) || captionalways) + (D_has_hstatus == HSTATUS_LASTLINE);
+  if (he < minhe)
+    {
+      debug1("too small, new height: %d\n", minhe);
+      he = minhe;
+    }
   cv->c_xe = wi - 1;
-  cv->c_ye = he - 1 - ((cv->c_slperp && cv->c_slperp->c_slnext) || captionalways) - (D_has_hstatus == HSTATUS_LASTLINE);
+  cv->c_ye = he - minhe;
   cv->c_blank.l_height = cv->c_ye - cv->c_ys + 1;
   if (cv->c_slperp)
     {
-- 
1.7.7.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.