Skip to content

Commit b963442

Browse files
committed
Fixed memory leak and crash in password functions
1 parent 3ee2ef8 commit b963442

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

Client/mods/deathmatch/logic/lua/CLuaFunctionRef.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ int CLuaFunctionRef::ToInt ( void ) const
140140
return m_iFunction;
141141
}
142142

143+
// Returns null if VM has closed
143144
lua_State* CLuaFunctionRef::GetLuaVM ( void ) const
144145
{
145146
return m_luaVM;

Shared/mods/deathmatch/logic/luadefs/CLuaCryptDefs.cpp

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -230,18 +230,22 @@ int CLuaCryptDefs::PasswordHash(lua_State* luaVM)
230230
// Execute time-consuming task
231231
return SharedUtil::BcryptHash(password, salt, cost);
232232

233-
}, [luaFunctionRef, pLuaMain](const SString& hash) {
234-
CLuaArguments arguments;
235-
236-
if (hash.empty())
233+
}, [luaFunctionRef](const SString& hash) {
234+
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaFunctionRef.GetLuaVM());
235+
if (pLuaMain)
237236
{
238-
m_pScriptDebugging->LogCustom(pLuaMain->GetVM(), "Invalid value for field 'salt'");
239-
arguments.PushBoolean(false);
240-
}
241-
else
242-
arguments.PushString(hash);
237+
CLuaArguments arguments;
243238

244-
arguments.Call(pLuaMain, luaFunctionRef);
239+
if (hash.empty())
240+
{
241+
m_pScriptDebugging->LogCustom(pLuaMain->GetVM(), "Invalid value for field 'salt'");
242+
arguments.PushBoolean(false);
243+
}
244+
else
245+
arguments.PushString(hash);
246+
247+
arguments.Call(pLuaMain, luaFunctionRef);
248+
}
245249
});
246250

247251
lua_pushboolean(luaVM, true);
@@ -295,11 +299,14 @@ int CLuaCryptDefs::PasswordVerify(lua_State* luaVM)
295299
// Execute time-consuming task
296300
return SharedUtil::BcryptVerify(password, hash);
297301

298-
}, [luaFunctionRef, pLuaMain](const bool& correct) {
299-
CLuaArguments arguments;
300-
arguments.PushBoolean(correct);
301-
302-
arguments.Call(pLuaMain, luaFunctionRef);
302+
}, [luaFunctionRef](const bool& correct) {
303+
CLuaMain* pLuaMain = m_pLuaManager->GetVirtualMachine(luaFunctionRef.GetLuaVM());
304+
if (pLuaMain)
305+
{
306+
CLuaArguments arguments;
307+
arguments.PushBoolean(correct);
308+
arguments.Call(pLuaMain, luaFunctionRef);
309+
}
303310
});
304311

305312
lua_pushboolean(luaVM, true);

Shared/sdk/SharedUtil.AsyncTaskScheduler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace SharedUtil
1919
{
2020
struct SBaseTask
2121
{
22+
virtual ~SBaseTask() {}
2223
virtual void Execute() = 0;
2324
virtual void ProcessResult() = 0;
2425
};

0 commit comments

Comments
 (0)