blob: 60a41259715c8a68f0de1bd87baedd721ae97430 [file] [log] [blame]
Andrew Geisslerbffdb3e2020-08-21 16:13:29 -05001From 6298903e35217ab69c279056f925fb72900ce0b7 Mon Sep 17 00:00:00 2001
2From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
3Date: Mon, 6 Jul 2020 12:11:54 -0300
4Subject: [PATCH] Keep minimum size when shrinking a stack
5
6When shrinking a stack (during GC), do not make it smaller than the
7initial stack size.
8---
9 ldo.c | 5 ++---
10 1 file changed, 2 insertions(+), 3 deletions(-)
11==== end of original header ====
12
13CVE: CVE-2020-15888
14
15Upstream-Status: backport [https://github.com/lua/lua.git]
16
17Signed-off-by: Joe Slater <joe.slater@windriver.com>
18
19====
20diff --git a/ldo.c b/ldo.c
21index c563b1d9..a89ac010 100644
22--- a/src/ldo.c
23+++ b/src/ldo.c
24@@ -220,7 +220,7 @@ static int stackinuse (lua_State *L) {
25
26 void luaD_shrinkstack (lua_State *L) {
27 int inuse = stackinuse(L);
28- int goodsize = inuse + (inuse / 8) + 2*EXTRA_STACK;
29+ int goodsize = inuse + BASIC_STACK_SIZE;
30 if (goodsize > LUAI_MAXSTACK)
31 goodsize = LUAI_MAXSTACK; /* respect stack limit */
32 if (L->stacksize > LUAI_MAXSTACK) /* had been handling stack overflow? */
33@@ -229,8 +229,7 @@ void luaD_shrinkstack (lua_State *L) {
34 luaE_shrinkCI(L); /* shrink list */
35 /* if thread is currently not handling a stack overflow and its
36 good size is smaller than current size, shrink its stack */
37- if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) &&
38- goodsize < L->stacksize)
39+ if (inuse <= (LUAI_MAXSTACK - EXTRA_STACK) && goodsize < L->stacksize)
40 luaD_reallocstack(L, goodsize);
41 else /* don't change stack */
42 condmovestack(L,{},{}); /* (change only for debugging) */
43--
442.17.1
45