summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKuang-che Wu <kcwu@csie.org>2015-08-31 17:49:57 +0000
committerAmadeusz Sławiński <amade@asmblr.net>2015-08-31 17:55:25 +0000
commitb7484c224738247b510ed0d268cd577076958f1b (patch)
treead2ef227fdfe6e39c65ee6897315215ea6db367d
parent03b85024504fb1e7cea0c289a16bbe887fa86bc9 (diff)
downloadscreen-b7484c224738247b510ed0d268cd577076958f1b.tar.gz
Fix stack overflow due to too deep recursion
Bug: 45713 How to reproduce: Run this command inside screen $ printf '\x1b[10000000T' screen will recursively call MScrollV to depth n/256. This is time consuming and will overflow stack if n is huge.
-rw-r--r--src/ansi.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/ansi.c b/src/ansi.c
index a342fb1..152d2ef 100644
--- a/src/ansi.c
+++ b/src/ansi.c
@@ -2502,13 +2502,13 @@ int n, ys, ye, bce;
return;
if (n > 0)
{
+ if (ye - ys + 1 < n)
+ n = ye - ys + 1;
if (n > 256)
{
MScrollV(p, n - 256, ys, ye, bce);
n = 256;
}
- if (ye - ys + 1 < n)
- n = ye - ys + 1;
#ifdef COPY_PASTE
if (compacthist)
{
@@ -2562,14 +2562,14 @@ int n, ys, ye, bce;
}
else
{
- if (n < -256)
- {
- MScrollV(p, n + 256, ys, ye, bce);
- n = -256;
- }
n = -n;
if (ye - ys + 1 < n)
n = ye - ys + 1;
+ if (n > 256)
+ {
+ MScrollV(p, - (n - 256), ys, ye, bce);
+ n = 256;
+ }
ml = p->w_mlines + ye;
/* Clear lines */