From 8a0d924baf23388c3b4e8669f1644ace53206e8e Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 21 Sep 2021 17:51:54 -0400 Subject: [PATCH] ncplane_erase_region(): protect against overflow --- src/lib/notcurses.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 06e13162b..18793d025 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -2144,7 +2144,7 @@ int ncplane_erase_region(ncplane* n, int ystart, int xstart, int ylen, int xlen) xstart = 0; xlen = ncplane_dim_x(n); } - if(xstart + xlen > ncplane_dim_x(n)){ + if(xlen > ncplane_dim_x(n) || xstart + xlen > ncplane_dim_x(n)){ xlen = ncplane_dim_x(n) - xstart; } if(ylen < 0){ @@ -2154,7 +2154,7 @@ int ncplane_erase_region(ncplane* n, int ystart, int xstart, int ylen, int xlen) ystart = 0; ylen = ncplane_dim_y(n); } - if(ystart + ylen > ncplane_dim_y(n)){ + if(ylen > ncplane_dim_y(n) || ystart + ylen > ncplane_dim_y(n)){ ylen = ncplane_dim_y(n) - ystart; } // special-case the full plane erasure, as it's powerfully optimized (O(1))