Skip to content

Commit abe9f17

Browse files
committed
cmake: use fine-grained UBsan suppressions in Lua
Closes #128
1 parent a7c2eca commit abe9f17

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed

cmake/BuildLua.cmake

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,8 @@ macro(build_lua LUA_VERSION)
3636

3737
if (ENABLE_UBSAN)
3838
string(JOIN "," NO_SANITIZE_FLAGS
39-
# lvm.c:luaV_execute()
40-
float-divide-by-zero
41-
# lgc.c:sweepstep()
42-
implicit-integer-sign-change
43-
# lvm.c:luaV_execute()
44-
integer-divide-by-zero
4539
# The object size sanitizer has no effect at -O0.
4640
object-size
47-
# lstring.c:luaS_hash()
48-
shift
49-
# lstring.c:luaS_hash()
50-
unsigned-integer-overflow
51-
# lstring.c:luaS_hash()
52-
unsigned-shift-base
5341
)
5442
string(JOIN " " ASAN_FLAGS
5543
-fsanitize=undefined

patches/puc-rio-lua.patch

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,41 @@
1+
diff --git a/lgc.c b/lgc.c
2+
index 0f89451c..c100b44b 100644
3+
--- a/lgc.c
4+
+++ b/lgc.c
5+
@@ -1585,6 +1585,7 @@ static void atomic (lua_State *L) {
6+
** Do a sweep step. The normal case (not fast) sweeps at most GCSWEEPMAX
7+
** elements. The fast case sweeps the whole list.
8+
*/
9+
+__attribute__((no_sanitize("implicit-integer-sign-change")))
10+
static void sweepstep (lua_State *L, global_State *g,
11+
lu_byte nextstate, GCObject **nextlist, int fast) {
12+
if (g->sweepgc)
13+
diff --git a/lstring.c b/lstring.c
14+
index 75635142..72411834 100644
15+
--- a/lstring.c
16+
+++ b/lstring.c
17+
@@ -49,7 +49,7 @@ int luaS_eqstr (TString *a, TString *b) {
18+
(memcmp(s1, s2, len1) == 0)); /* equal contents */
19+
}
20+
21+
-
22+
+__attribute__((no_sanitize("shift", "unsigned-integer-overflow", "unsigned-shift-base")))
23+
static unsigned luaS_hash (const char *str, size_t l, unsigned seed) {
24+
unsigned int h = seed ^ cast_uint(l);
25+
for (; l > 0; l--)
26+
diff --git a/lvm.c b/lvm.c
27+
index c70e2b8a..3e3274de 100644
28+
--- a/lvm.c
29+
+++ b/lvm.c
30+
@@ -1194,7 +1194,7 @@ void luaV_finishOp (lua_State *L) {
31+
#define vmcase(l) case l:
32+
#define vmbreak break
33+
34+
-
35+
+__attribute__((no_sanitize("float-divide-by-zero", "integer-divide-by-zero")))
36+
void luaV_execute (lua_State *L, CallInfo *ci) {
37+
LClosure *cl;
38+
TValue *k;
139
diff --git a/makefile b/makefile
240
index 8674519f..dd0fb23e 100644
341
--- a/makefile

0 commit comments

Comments
 (0)