Lua 有什么防止缓冲区过度读取的方法吗?

我一直在研究 Lua 源代码,我找到了虚拟机获取下一条指令的位置,就在 vmfetch 宏的第一行:

#define vmfetch()       { \
  i = *(ci->u.l.savedpc++); \
  if (L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) \
    Protect(luaG_traceexec(L)); \
  ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \
  lua_assert(base == ci->u.l.base); \
  lua_assert(base <= L->top && L->top < L->stack + L->stacksize); \
}

然而,我发现在 vmfetchluaV_execute 中都没有代码检查 ci->u.l.savedpc++ 是否是有效地址,因此我想知道 Lua 是如何防止意外执行某些随机地址的数据的?

点赞
用户5129715
用户5129715

原文

The protection is in the compilation phase. The byte-code generation, would not build a chunk without some termination in it.

Allowing your users to add compiled lua, without any "trust" is a vulnerability. Games such as WoW - which allow user lua, only accept source code, ensuring they have control over the compilation process.

翻译

保护措施是在编译阶段进行的。字节码生成不会构建没有终止符的代码块。

允许用户在没有"信任"的情况下添加编译好的 Lua 代码是一种漏洞。像《魔兽世界》这样允许用户使用 Lua 的游戏,只接受源代码,以确保他们对编译过程拥有控制权。

2018-09-23 09:15:58