Skip to content

Commit 0c9b5c9

Browse files
authored
Fix metatable security (#309)
* Set __metatable to false instead of nil * Also set __metatable when constructing a Namespace
1 parent 4a1cde6 commit 0c9b5c9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Source/LuaBridge/detail/Namespace.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class Namespace : public detail::Registrar
155155

156156
if (Security::hideMetatables())
157157
{
158-
lua_pushnil(L);
158+
lua_pushboolean(L, 0);
159159
rawsetfield(L, -2, "__metatable");
160160
}
161161
}
@@ -221,7 +221,7 @@ class Namespace : public detail::Registrar
221221

222222
if (Security::hideMetatables())
223223
{
224-
lua_pushnil(L);
224+
lua_pushboolean(L, 0);
225225
rawsetfield(L, -2, "__metatable");
226226
}
227227
}
@@ -1041,6 +1041,12 @@ class Namespace : public detail::Registrar
10411041
lua_newtable(L); // Stack: pns, ns, propset table (ps)
10421042
lua_rawsetp(L, -2, detail::getPropsetKey()); // ns [propsetKey] = ps. Stack: pns, ns
10431043

1044+
if (Security::hideMetatables())
1045+
{
1046+
lua_pushboolean(L, 0);
1047+
rawsetfield(L, -2, "__metatable");
1048+
}
1049+
10441050
// pns [name] = ns
10451051
lua_pushvalue(L, -1); // Stack: pns, ns, ns
10461052
rawsetfield(L, -3, name); // Stack: pns, ns

0 commit comments

Comments
 (0)