aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorparadust7 <102263465+paradust7@users.noreply.github.com>2022-05-21 08:46:50 -0700
committerGitHub <noreply@github.com>2022-05-21 17:46:50 +0200
commite1f707d7e1ac0412eedbfcc200a1b90339d3ab0d (patch)
tree29fbb9b12238696e6f67c9e81563d77f8279769a
parent9ee3dc71f1bb094c04afe98832f69f2a95995340 (diff)
downloadminetest-e1f707d7e1ac0412eedbfcc200a1b90339d3ab0d.tar.gz
minetest-e1f707d7e1ac0412eedbfcc200a1b90339d3ab0d.tar.bz2
minetest-e1f707d7e1ac0412eedbfcc200a1b90339d3ab0d.zip
Patch built-in Lua to fix miscompile on Android (#12347)
-rw-r--r--lib/lua/src/lgc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/lua/src/lgc.c b/lib/lua/src/lgc.c
index e909c79a9..9141a1c60 100644
--- a/lib/lua/src/lgc.c
+++ b/lib/lua/src/lgc.c
@@ -164,8 +164,13 @@ static int traversetable (global_State *g, Table *h) {
markobject(g, h->metatable);
mode = gfasttm(g, h->metatable, TM_MODE);
if (mode && ttisstring(mode)) { /* is there a weak mode? */
- weakkey = (strchr(svalue(mode), 'k') != NULL);
- weakvalue = (strchr(svalue(mode), 'v') != NULL);
+ // Android's 'FORTIFY libc' calls __builtin_object_size on the argument of strchr.
+ // This produces an incorrect size for the expression `svalue(mode)`, causing
+ // an assertion. By placing it in a temporary, __builtin_object_size returns
+ // -1 (for unknown size) which functions correctly.
+ const char *tmp = svalue(mode);
+ weakkey = (strchr(tmp, 'k') != NULL);
+ weakvalue = (strchr(tmp, 'v') != NULL);
if (weakkey || weakvalue) { /* is really weak? */
h->marked &= ~(KEYWEAK | VALUEWEAK); /* clear bits */
h->marked |= cast_byte((weakkey << KEYWEAKBIT) |