Skip to content

Commit 45e32c4

Browse files
Revert "Enable Lua packages and Lua C packages"
This reverts commit 0613d87.
1 parent ff2a8d6 commit 45e32c4

File tree

3 files changed

+10
-88
lines changed

3 files changed

+10
-88
lines changed

Server/mods/deathmatch/logic/lua/CLuaMain.cpp

Lines changed: 9 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ CLuaMain::CLuaMain ( CLuaManager* pLuaManager,
6363

6464
m_bEnableOOP = bEnableOOP;
6565

66-
m_iPackageRef = -1;
6766

6867
CPerfStatLuaMemory::GetSingleton ()->OnLuaMainCreate ( this );
6968
CPerfStatLuaTiming::GetSingleton ()->OnLuaMainCreate ( this );
@@ -127,33 +126,13 @@ void CLuaMain::InitSecurity ( void )
127126
{
128127
lua_register ( m_luaVM, "dofile", CLuaUtilDefs::DisabledFunction );
129128
lua_register ( m_luaVM, "loadfile", CLuaUtilDefs::DisabledFunction );
129+
lua_register ( m_luaVM, "require", CLuaUtilDefs::DisabledFunction );
130+
lua_register ( m_luaVM, "loadlib", CLuaUtilDefs::DisabledFunction );
130131
lua_register ( m_luaVM, "getfenv", CLuaUtilDefs::DisabledFunction );
131132
lua_register ( m_luaVM, "newproxy", CLuaUtilDefs::DisabledFunction );
132133
}
133134

134135

135-
void CLuaMain::InitPackageSecurity(void)
136-
{
137-
// Grab our original package library
138-
lua_getglobal(m_luaVM, "package"); // stack: [tbl_package]
139-
140-
// Create a new package library, with only whitelisted functions
141-
lua_newtable(m_luaVM); // stack: [tbl_package,tbl_new]
142-
std::vector<const char*> szWhitelist = { "loaded", "seeall" };
143-
for (auto it = szWhitelist.begin(); it != szWhitelist.end(); it++)
144-
{
145-
lua_pushstring(m_luaVM, *it); // stack: [tbl_package,tbl_new,"loaded"]
146-
lua_pushstring(m_luaVM, *it); // stack: [tbl_package,tbl_new,"loaded","loaded"]
147-
lua_gettable(m_luaVM, -4); // stack: [tbl_package,tbl_new,"loaded",package.loaded]
148-
lua_settable(m_luaVM, -3); // stack: [tbl_package,tbl_new]
149-
}
150-
lua_setglobal(m_luaVM, "package"); // stack: [tbl_package]
151-
152-
// Keep the original package library safe in the registry
153-
m_iPackageRef = luaL_ref(m_luaVM, LUA_REGISTRYINDEX); // stack: []
154-
}
155-
156-
157136
void CLuaMain::InitClasses ( lua_State* luaVM )
158137
{
159138
lua_initclasses ( luaVM );
@@ -206,27 +185,13 @@ void CLuaMain::InitVM ( void )
206185
lua_sethook ( m_luaVM, InstructionCountHook, LUA_MASKCOUNT, HOOK_INSTRUCTION_COUNT );
207186

208187
// Load LUA libraries
209-
const luaL_Reg lualibs[] = {
210-
{ "", luaopen_base },
211-
{ LUA_LOADLIBNAME, luaopen_package },
212-
{ LUA_TABLIBNAME, luaopen_table },
213-
{ LUA_STRLIBNAME, luaopen_string },
214-
{ LUA_MATHLIBNAME, luaopen_math },
215-
{ LUA_DBLIBNAME, luaopen_debug },
216-
{ "utf8", luaopen_utf8 },
217-
{ NULL, NULL }
218-
};
219-
220-
const luaL_Reg *lib = lualibs;
221-
for (; lib->func; lib++) {
222-
lua_pushcfunction(m_luaVM, lib->func);
223-
lua_pushstring(m_luaVM, lib->name);
224-
lua_call(m_luaVM, 1, 0);
225-
}
226-
227-
// Initialize our customized 'package' library with restricted functions
228-
InitPackageSecurity ();
229-
188+
luaopen_base ( m_luaVM );
189+
luaopen_math ( m_luaVM );
190+
luaopen_string ( m_luaVM );
191+
luaopen_table ( m_luaVM );
192+
luaopen_debug ( m_luaVM );
193+
luaopen_utf8 ( m_luaVM );
194+
230195
// Initialize security restrictions. Very important to prevent lua trojans and viruses!
231196
InitSecurity ();
232197

@@ -721,39 +686,3 @@ int CLuaMain::OnUndump( const char* p, size_t n )
721686
}
722687
return 1;
723688
}
724-
725-
726-
///////////////////////////////////////////////////////////////
727-
//
728-
// CLuaMain::SetPackagePaths
729-
//
730-
// Sets module directories for pure lua and C lua modules
731-
//
732-
///////////////////////////////////////////////////////////////
733-
bool CLuaMain::SetPackagePaths(SString strPath, SString strCPath)
734-
{
735-
if (!m_luaVM || m_iPackageRef < 0 )
736-
return false;
737-
738-
// Setup our wildcards for searching
739-
strPath = PathJoin(strPath, "?.lua") + ";" + PathJoin(strPath, "?/init.lua");
740-
741-
#ifdef WIN32
742-
strCPath = PathJoin(strCPath, "?.dll");
743-
#else
744-
strCPath = PathJoin(strCPath, "?.so");
745-
#endif
746-
747-
// Overwrite our path variable function from the registry (saved earlier)
748-
lua_rawgeti(m_luaVM, LUA_REGISTRYINDEX, m_iPackageRef); // stack: [tbl_hiddenPackage]
749-
lua_pushstring(m_luaVM, "path"); // stack: [tbl_hiddenPackage,"path"]
750-
lua_pushstring(m_luaVM, strPath.c_str()); // stack: [tbl_hiddenPackage,"path","C:/someresource/?.lua"]
751-
lua_settable(m_luaVM, -3); // stack: [tbl_hiddenPackage]
752-
753-
lua_pushstring(m_luaVM, "cpath"); // stack: [tbl_hiddenPackage,"cpath"]
754-
lua_pushstring(m_luaVM, strCPath.c_str()); // stack: [tbl_hiddenPackage,"cpath","C:/somemodules/?.dll"]
755-
lua_settable(m_luaVM, -3); // stack: [tbl_hiddenPackage]
756-
lua_pop(m_luaVM, -1); // stack: []
757-
758-
return true;
759-
}

Server/mods/deathmatch/logic/lua/CLuaMain.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,8 @@ class CLuaMain //: public CClient
120120
static int LuaLoadBuffer ( lua_State *L, const char *buff, size_t sz, const char *name );
121121
static int OnUndump ( const char* p, size_t n );
122122

123-
bool SetPackagePaths ( SString strPath, SString strCPath );
124-
125123
private:
126124
void InitSecurity ( void );
127-
void InitPackageSecurity ( void );
128125
void InitClasses ( lua_State* luaVM );
129126

130127
public:
@@ -137,7 +134,6 @@ class CLuaMain //: public CClient
137134
SString m_strScriptName;
138135

139136
lua_State* m_luaVM;
140-
int m_iPackageRef;
141137
CLuaTimerManager* m_pLuaTimerManager;
142138

143139
class CResource* m_pResource;

Server/mods/deathmatch/logic/lua/CLuaManager.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ CLuaMain * CLuaManager::CreateVirtualMachine ( CResource* pResourceOwner, bool b
7676
CLuaMain * pLuaMain = new CLuaMain ( this, m_pObjectManager, m_pPlayerManager, m_pVehicleManager, m_pBlipManager, m_pRadarAreaManager, m_pMapManager, pResourceOwner, bEnableOOP );
7777
m_virtualMachines.push_back ( pLuaMain );
7878
pLuaMain->InitVM ();
79-
pLuaMain->SetPackagePaths(
80-
pResourceOwner->IsResourceZip() ? pResourceOwner->GetResourceCacheDirectoryPath() : pResourceOwner->GetResourceDirectoryPath(),
81-
PathJoin(g_pServerInterface->GetModManager()->GetServerPath(), SERVER_BIN_PATH_MOD, "modules")
82-
);
79+
8380
m_pLuaModuleManager->RegisterFunctions ( pLuaMain->GetVirtualMachine() );
8481

8582
return pLuaMain;

0 commit comments

Comments
 (0)