add upstream fixes for Bugs 8 and 9
This commit is contained in:
parent
1aadd02a4d
commit
20fcaf120e
136
lua-5.4.4-bug8.patch
Normal file
136
lua-5.4.4-bug8.patch
Normal file
@ -0,0 +1,136 @@
|
||||
diff -up lua-5.4.4/lua-5.4.4-tests/utf8.lua.bug8 lua-5.4.4/lua-5.4.4-tests/utf8.lua
|
||||
--- lua-5.4.4/lua-5.4.4-tests/utf8.lua.bug8 2023-02-14 14:53:22.877506883 -0500
|
||||
+++ lua-5.4.4/lua-5.4.4-tests/utf8.lua 2023-02-14 14:53:28.297574398 -0500
|
||||
@@ -97,9 +97,15 @@ do -- error indication in utf8.len
|
||||
assert(not a and b == p)
|
||||
end
|
||||
check("abc\xE3def", 4)
|
||||
- check("汉字\x80", #("汉字") + 1)
|
||||
check("\xF4\x9F\xBF", 1)
|
||||
check("\xF4\x9F\xBF\xBF", 1)
|
||||
+ -- spurious continuation bytes
|
||||
+ check("汉字\x80", #("汉字") + 1)
|
||||
+ check("\x80hello", 1)
|
||||
+ check("hel\x80lo", 4)
|
||||
+ check("汉字\xBF", #("汉字") + 1)
|
||||
+ check("\xBFhello", 1)
|
||||
+ check("hel\xBFlo", 4)
|
||||
end
|
||||
|
||||
-- errors in utf8.codes
|
||||
@@ -112,12 +118,16 @@ do
|
||||
end
|
||||
errorcodes("ab\xff")
|
||||
errorcodes("\u{110000}")
|
||||
+ errorcodes("in\x80valid")
|
||||
+ errorcodes("\xbfinvalid")
|
||||
+ errorcodes("αλφ\xBFα")
|
||||
|
||||
-- calling interation function with invalid arguments
|
||||
local f = utf8.codes("")
|
||||
assert(f("", 2) == nil)
|
||||
assert(f("", -1) == nil)
|
||||
assert(f("", math.mininteger) == nil)
|
||||
+
|
||||
end
|
||||
|
||||
-- error in initial position for offset
|
||||
diff -up lua-5.4.4/src/lutf8lib.c.bug8 lua-5.4.4/src/lutf8lib.c
|
||||
--- lua-5.4.4/src/lutf8lib.c.bug8 2023-02-14 14:53:49.114833691 -0500
|
||||
+++ lua-5.4.4/src/lutf8lib.c 2023-02-14 14:59:12.660905056 -0500
|
||||
@@ -25,6 +25,9 @@
|
||||
|
||||
#define MAXUTF 0x7FFFFFFFu
|
||||
|
||||
+
|
||||
+#define MSGInvalid "invalid UTF-8 code"
|
||||
+
|
||||
/*
|
||||
** Integer type for decoded UTF-8 values; MAXUTF needs 31 bits.
|
||||
*/
|
||||
@@ -35,7 +38,8 @@ typedef unsigned long utfint;
|
||||
#endif
|
||||
|
||||
|
||||
-#define iscont(p) ((*(p) & 0xC0) == 0x80)
|
||||
+#define iscont(c) (((c) & 0xC0) == 0x80)
|
||||
+#define iscontp(p) iscont(*(p))
|
||||
|
||||
|
||||
/* from strlib */
|
||||
@@ -65,7 +69,7 @@ static const char *utf8_decode (const ch
|
||||
int count = 0; /* to count number of continuation bytes */
|
||||
for (; c & 0x40; c <<= 1) { /* while it needs continuation bytes... */
|
||||
unsigned int cc = (unsigned char)s[++count]; /* read next byte */
|
||||
- if ((cc & 0xC0) != 0x80) /* not a continuation byte? */
|
||||
+ if (!iscont(cc)) /* not a continuation byte? */
|
||||
return NULL; /* invalid byte sequence */
|
||||
res = (res << 6) | (cc & 0x3F); /* add lower 6 bits from cont. byte */
|
||||
}
|
||||
@@ -140,7 +144,7 @@ static int codepoint (lua_State *L) {
|
||||
utfint code;
|
||||
s = utf8_decode(s, &code, !lax);
|
||||
if (s == NULL)
|
||||
- return luaL_error(L, "invalid UTF-8 code");
|
||||
+ return luaL_error(L, MSGInvalid);
|
||||
lua_pushinteger(L, code);
|
||||
n++;
|
||||
}
|
||||
@@ -190,16 +194,16 @@ static int byteoffset (lua_State *L) {
|
||||
"position out of bounds");
|
||||
if (n == 0) {
|
||||
/* find beginning of current byte sequence */
|
||||
- while (posi > 0 && iscont(s + posi)) posi--;
|
||||
+ while (posi > 0 && iscontp(s + posi)) posi--;
|
||||
}
|
||||
else {
|
||||
- if (iscont(s + posi))
|
||||
+ if (iscontp(s + posi))
|
||||
return luaL_error(L, "initial position is a continuation byte");
|
||||
if (n < 0) {
|
||||
while (n < 0 && posi > 0) { /* move back */
|
||||
do { /* find beginning of previous character */
|
||||
posi--;
|
||||
- } while (posi > 0 && iscont(s + posi));
|
||||
+ } while (posi > 0 && iscontp(s + posi));
|
||||
n++;
|
||||
}
|
||||
}
|
||||
@@ -208,7 +212,7 @@ static int byteoffset (lua_State *L) {
|
||||
while (n > 0 && posi < (lua_Integer)len) {
|
||||
do { /* find beginning of next character */
|
||||
posi++;
|
||||
- } while (iscont(s + posi)); /* (cannot pass final '\0') */
|
||||
+ } while (iscontp(s + posi)); /* (cannot pass final '\0') */
|
||||
n--;
|
||||
}
|
||||
}
|
||||
@@ -226,15 +230,15 @@ static int iter_aux (lua_State *L, int s
|
||||
const char *s = luaL_checklstring(L, 1, &len);
|
||||
lua_Unsigned n = (lua_Unsigned)lua_tointeger(L, 2);
|
||||
if (n < len) {
|
||||
- while (iscont(s + n)) n++; /* skip continuation bytes */
|
||||
+ while (iscontp(s + n)) n++; /* go to next character */
|
||||
}
|
||||
if (n >= len) /* (also handles original 'n' being negative) */
|
||||
return 0; /* no more codepoints */
|
||||
else {
|
||||
utfint code;
|
||||
const char *next = utf8_decode(s + n, &code, strict);
|
||||
- if (next == NULL)
|
||||
- return luaL_error(L, "invalid UTF-8 code");
|
||||
+ if (next == NULL || iscontp(next))
|
||||
+ return luaL_error(L, MSGInvalid);
|
||||
lua_pushinteger(L, n + 1);
|
||||
lua_pushinteger(L, code);
|
||||
return 2;
|
||||
@@ -253,7 +257,8 @@ static int iter_auxlax (lua_State *L) {
|
||||
|
||||
static int iter_codes (lua_State *L) {
|
||||
int lax = lua_toboolean(L, 2);
|
||||
- luaL_checkstring(L, 1);
|
||||
+ const char *s = luaL_checkstring(L, 1);
|
||||
+ luaL_argcheck(L, !iscontp(s), 1, MSGInvalid);
|
||||
lua_pushcfunction(L, lax ? iter_auxlax : iter_auxstrict);
|
||||
lua_pushvalue(L, 1);
|
||||
lua_pushinteger(L, 0);
|
115
lua-5.4.4-bug9.patch
Normal file
115
lua-5.4.4-bug9.patch
Normal file
@ -0,0 +1,115 @@
|
||||
From 1e64c1391f9a14115b5cc82066dbf545ae73ee27 Mon Sep 17 00:00:00 2001
|
||||
From: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
|
||||
Date: Tue, 25 Oct 2022 16:44:06 -0300
|
||||
Subject: [PATCH] Bug: stack overflow with nesting of coroutine.close
|
||||
|
||||
---
|
||||
lcorolib.c | 4 ++--
|
||||
lstate.c | 3 ++-
|
||||
ltests.c | 2 +-
|
||||
lua.h | 2 +-
|
||||
manual/manual.of | 7 ++++++-
|
||||
testes/cstack.lua | 26 ++++++++++++++++++++++++++
|
||||
6 files changed, 38 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/lcorolib.c b/lcorolib.c
|
||||
index 785a1e81a..40b880b14 100644
|
||||
--- a/src/lcorolib.c
|
||||
+++ b/src/lcorolib.c
|
||||
@@ -76,7 +76,7 @@ static int luaB_auxwrap (lua_State *L) {
|
||||
if (l_unlikely(r < 0)) { /* error? */
|
||||
int stat = lua_status(co);
|
||||
if (stat != LUA_OK && stat != LUA_YIELD) { /* error in the coroutine? */
|
||||
- stat = lua_resetthread(co); /* close its tbc variables */
|
||||
+ stat = lua_resetthread(co, L); /* close its tbc variables */
|
||||
lua_assert(stat != LUA_OK);
|
||||
lua_xmove(co, L, 1); /* move error message to the caller */
|
||||
}
|
||||
@@ -172,7 +172,7 @@ static int luaB_close (lua_State *L) {
|
||||
int status = auxstatus(L, co);
|
||||
switch (status) {
|
||||
case COS_DEAD: case COS_YIELD: {
|
||||
- status = lua_resetthread(co);
|
||||
+ status = lua_resetthread(co, L);
|
||||
if (status == LUA_OK) {
|
||||
lua_pushboolean(L, 1);
|
||||
return 1;
|
||||
diff --git a/lstate.c b/lstate.c
|
||||
index 1ffe1a0f7..4b5c10008 100644
|
||||
--- a/src/lstate.c
|
||||
+++ b/src/lstate.c
|
||||
@@ -343,9 +343,10 @@ int luaE_resetthread (lua_State *L, int status) {
|
||||
}
|
||||
|
||||
|
||||
-LUA_API int lua_resetthread (lua_State *L) {
|
||||
+LUA_API int lua_resetthread (lua_State *L, lua_State *from) {
|
||||
int status;
|
||||
lua_lock(L);
|
||||
+ L->nCcalls = (from) ? getCcalls(from) : 0;
|
||||
status = luaE_resetthread(L, L->status);
|
||||
lua_unlock(L);
|
||||
return status;
|
||||
diff --git a/ltests.c b/ltests.c
|
||||
index 9a887f981..734a96dae 100644
|
||||
--- a/lua-5.4.4-tests/ltests/ltests.c
|
||||
+++ b/lua-5.4.4-tests/ltests/ltests.c
|
||||
@@ -1533,7 +1533,7 @@ static int runC (lua_State *L, lua_State *L1, const char *pc) {
|
||||
lua_newthread(L1);
|
||||
}
|
||||
else if EQ("resetthread") {
|
||||
- lua_pushinteger(L1, lua_resetthread(L1));
|
||||
+ lua_pushinteger(L1, lua_resetthread(L1, L));
|
||||
}
|
||||
else if EQ("newuserdata") {
|
||||
lua_newuserdata(L1, getnum);
|
||||
diff --git a/lua.h b/lua.h
|
||||
index 219784cc0..bfba4d1e1 100644
|
||||
--- a/src/lua.h
|
||||
+++ b/src/lua.h
|
||||
@@ -153,7 +153,7 @@ extern const char lua_ident[];
|
||||
LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);
|
||||
LUA_API void (lua_close) (lua_State *L);
|
||||
LUA_API lua_State *(lua_newthread) (lua_State *L);
|
||||
-LUA_API int (lua_resetthread) (lua_State *L);
|
||||
+LUA_API int (lua_resetthread) (lua_State *L, lua_State *from);
|
||||
|
||||
LUA_API lua_CFunction (lua_atpanic) (lua_State *L, lua_CFunction panicf);
|
||||
|
||||
diff --git a/testes/cstack.lua b/testes/cstack.lua
|
||||
index ca76c8729..97afe9fd0 100644
|
||||
--- a/lua-5.4.4-tests/cstack.lua
|
||||
+++ b/lua-5.4.4-tests/cstack.lua
|
||||
@@ -84,6 +84,32 @@ do -- bug in 5.4.0
|
||||
end
|
||||
|
||||
|
||||
+do -- bug since 5.4.0
|
||||
+ local count = 0
|
||||
+ print("chain of 'coroutine.close'")
|
||||
+ -- create N coroutines forming a list so that each one, when closed,
|
||||
+ -- closes the previous one. (With a large enough N, previous Lua
|
||||
+ -- versions crash in this test.)
|
||||
+ local coro = false
|
||||
+ for i = 1, 1000 do
|
||||
+ local previous = coro
|
||||
+ coro = coroutine.create(function()
|
||||
+ local cc <close> = setmetatable({}, {__close=function()
|
||||
+ count = count + 1
|
||||
+ if previous then
|
||||
+ assert(coroutine.close(previous))
|
||||
+ end
|
||||
+ end})
|
||||
+ coroutine.yield() -- leaves 'cc' pending to be closed
|
||||
+ end)
|
||||
+ assert(coroutine.resume(coro)) -- start it and run until it yields
|
||||
+ end
|
||||
+ local st, msg = coroutine.close(coro)
|
||||
+ assert(not st and string.find(msg, "C stack overflow"))
|
||||
+ print("final count: ", count)
|
||||
+end
|
||||
+
|
||||
+
|
||||
do
|
||||
print("nesting of resuming yielded coroutines")
|
||||
local count = 0
|
13
lua.spec
13
lua.spec
@ -14,7 +14,7 @@
|
||||
|
||||
Name: lua
|
||||
Version: %{major_version}.4
|
||||
Release: 8%{?dist}
|
||||
Release: 9%{?dist}
|
||||
Summary: Powerful light-weight programming language
|
||||
License: MIT
|
||||
URL: https://www.lua.org/
|
||||
@ -51,6 +51,12 @@ Patch11: https://github.com/lua/lua/commit/196bb94d66e727e0aec053a0276c3ad701500
|
||||
Patch12: https://github.com/lua/lua/commit/a1f77a234a053da46b06d5d4be00ffb30d3eb45b.patch
|
||||
# 5.4.4 http://lua-users.org/lists/lua-l/2022-02/msg00112.html
|
||||
Patch13: %{name}-5.4.4-luac-doublefree.patch
|
||||
# 5.4.4 Bug 8
|
||||
# https://github.com/lua/lua/commit/a1089b415a3f5c753aa1b40758ffdaf28d5701b0
|
||||
Patch14: lua-5.4.4-bug8.patch
|
||||
# 5.4.4 Bug 9
|
||||
# https://github.com/lua/lua/commit/1e64c1391f9a14115b5cc82066dbf545ae73ee27
|
||||
Patch15: lua-5.4.4-bug9.patch
|
||||
|
||||
|
||||
BuildRequires: automake autoconf libtool readline-devel ncurses-devel
|
||||
@ -113,6 +119,8 @@ mv src/luaconf.h src/luaconf.h.template.in
|
||||
%patch11 -p1 -b .5.4.4-bug5
|
||||
%patch12 -p1 -b .5.4.4-bug7
|
||||
%patch13 -p1 -b .5.4.4-doublefree
|
||||
%patch14 -p1 -b .5.4.4-bug8
|
||||
%patch15 -p1 -b .5.4.4-bug9
|
||||
# Put proper version in configure.ac, patch0 hardcodes 5.3.0
|
||||
sed -i 's|5.3.0|%{version}|g' configure.ac
|
||||
autoreconf -ifv
|
||||
@ -229,6 +237,9 @@ popd
|
||||
%{_libdir}/*.a
|
||||
|
||||
%changelog
|
||||
* Tue Feb 14 2023 Tom Callaway <spot@fedoraproject.org> - 5.4.4-9
|
||||
- add upstream fixes for Bugs 8 and 9
|
||||
|
||||
* Thu Jan 19 2023 Fedora Release Engineering <releng@fedoraproject.org> - 5.4.4-8
|
||||
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user