From c24fbda3021444581028224c33e391101bddce64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Gr=C3=BCnbacher?= Date: Mon, 11 May 2015 00:24:20 +0200 Subject: [PATCH] Engine: Add error path to DispatchKeyValue() based on g_inKeyValue This was unsafe as g_pkvd is pointed to a stack variable that is only valid while inside of pfn_keyvalue() --- modules/engine/entity.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/engine/entity.cpp b/modules/engine/entity.cpp index 2d572505..61d19d01 100644 --- a/modules/engine/entity.cpp +++ b/modules/engine/entity.cpp @@ -174,7 +174,13 @@ static cell AMX_NATIVE_CALL DispatchKeyValue(AMX *amx, cell *params) kvd.fHandled = 0; MDLL_KeyValue(pEntity, &kvd); - } else { + } else if (count == 2) { + if (!g_inKeyValue) + { + MF_LogError(amx, AMX_ERR_NATIVE, "DispatchKeyValue() with two arguments can only be used inside of pfn_keyvalue()"); + return 0; + } + int iLength; char *char1 = MF_GetAmxString(amx, params[1], 0, &iLength); char *char2 = MF_GetAmxString(amx, params[2], 1, &iLength);