|
| 1 | +From 3bb38d48f5e04d56ff7e08391dd17f902e7828ff Mon Sep 17 00:00:00 2001 |
| 2 | +From: npt-1707 <npthanh132@gmail.com> |
| 3 | +Date: Mon, 21 Apr 2025 23:05:53 +0800 |
| 4 | +Subject: [PATCH] Save stack space while handling errors |
| 5 | + |
| 6 | +Signed-off-by: Azure Linux Security Servicing Account <azurelinux-security@microsoft.com> |
| 7 | +Upstream-reference: https://github.com/praydog/REFramework/pull/1320.patch |
| 8 | +--- |
| 9 | + vendor/lua/src/ldebug.c | 5 ++++- |
| 10 | + vendor/lua/src/lvm.c | 6 ++++-- |
| 11 | + 2 files changed, 8 insertions(+), 3 deletions(-) |
| 12 | + |
| 13 | +diff --git a/vendor/lua/src/ldebug.c b/vendor/lua/src/ldebug.c |
| 14 | +index 1feaab2..5524fae 100644 |
| 15 | +--- a/vendor/lua/src/ldebug.c |
| 16 | ++++ b/vendor/lua/src/ldebug.c |
| 17 | +@@ -783,8 +783,11 @@ l_noret luaG_runerror (lua_State *L, const char *fmt, ...) { |
| 18 | + va_start(argp, fmt); |
| 19 | + msg = luaO_pushvfstring(L, fmt, argp); /* format message */ |
| 20 | + va_end(argp); |
| 21 | +- if (isLua(ci)) /* if Lua function, add source:line information */ |
| 22 | ++ if (isLua(ci)) { /* if Lua function, add source:line information */ |
| 23 | + luaG_addinfo(L, msg, ci_func(ci)->p->source, getcurrentline(ci)); |
| 24 | ++ setobjs2s(L, L->top - 2, L->top - 1); /* remove 'msg' from the stack */ |
| 25 | ++ L->top--; |
| 26 | ++ } |
| 27 | + luaG_errormsg(L); |
| 28 | + } |
| 29 | + |
| 30 | +diff --git a/vendor/lua/src/lvm.c b/vendor/lua/src/lvm.c |
| 31 | +index c9729bc..51b9614 100644 |
| 32 | +--- a/vendor/lua/src/lvm.c |
| 33 | ++++ b/vendor/lua/src/lvm.c |
| 34 | +@@ -656,8 +656,10 @@ void luaV_concat (lua_State *L, int total) { |
| 35 | + /* collect total length and number of strings */ |
| 36 | + for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { |
| 37 | + size_t l = vslen(s2v(top - n - 1)); |
| 38 | +- if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) |
| 39 | ++ if (l_unlikely(l >= (MAX_SIZE/sizeof(char)) - tl)) { |
| 40 | ++ L->top = top - total; /* pop strings to avoid wasting stack */ |
| 41 | + luaG_runerror(L, "string length overflow"); |
| 42 | ++ } |
| 43 | + tl += l; |
| 44 | + } |
| 45 | + if (tl <= LUAI_MAXSHORTLEN) { /* is result a short string? */ |
| 46 | +@@ -672,7 +674,7 @@ void luaV_concat (lua_State *L, int total) { |
| 47 | + setsvalue2s(L, top - n, ts); /* create result */ |
| 48 | + } |
| 49 | + total -= n-1; /* got 'n' strings to create 1 new */ |
| 50 | +- L->top -= n-1; /* popped 'n' strings and pushed one */ |
| 51 | ++ L->top = top - (n - 1); /* popped 'n' strings and pushed one */ |
| 52 | + } while (total > 1); /* repeat until only 1 result left */ |
| 53 | + } |
| 54 | + |
| 55 | +-- |
| 56 | +2.45.4 |
| 57 | + |
0 commit comments