From fab4a439158712b9ba916afcdba710605527dc2c Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 18 Jul 2006 04:39:54 +0000 Subject: [PATCH] Fix for am41317, forward re-entrancy problem --- amxmodx/amxmodx.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/amxmodx/amxmodx.cpp b/amxmodx/amxmodx.cpp index 8728dc90..09cf9c6d 100755 --- a/amxmodx/amxmodx.cpp +++ b/amxmodx/amxmodx.cpp @@ -3741,13 +3741,20 @@ static cell AMX_NATIVE_CALL ExecuteForward(AMX *amx, cell *params) { int id = static_cast(params[1]); int str_id = 0; - int len; + int len, err; cell *addr = get_amxaddr(amx, params[2]); if (!g_forwards.isIdValid(id)) return 0; + struct allot_info + { + cell amx_addr; + cell *phys_addr; + }; + cell ps[FORWARD_MAX_PARAMS]; + allot_info allots[FORWARD_MAX_PARAMS]; cell count = params[0] / sizeof(cell); if (count - 2 != g_forwards.getParamsNum(id)) { @@ -3757,13 +3764,32 @@ static cell AMX_NATIVE_CALL ExecuteForward(AMX *amx, cell *params) for (cell i=3; i<=count; i++) { if (g_forwards.getParamType(id, i-3) == FP_STRING) - ps[i-3] = reinterpret_cast(get_amxstring(amx, params[i], str_id++, len)); - else + { + char *tmp = get_amxstring(amx, params[i], 0, len); + cell num = len / sizeof(cell) + 1; + num += 4 - (num % 4); + if ((err=amx_Allot(amx, num, &allots[i-3].amx_addr, &allots[i-3].phys_addr)) != AMX_ERR_NONE) + { + LogError(amx, err, NULL); + return 0; + } + strcpy((char *)allots[i-3].phys_addr, tmp); + ps[i-3] = (cell)allots[i-3].phys_addr; + } else { ps[i-3] = *get_amxaddr(amx, params[i]); + } } *addr = g_forwards.executeForwards(id, ps); + for (cell i=3; i<=count; i++) + { + if (g_forwards.getParamType(id, i-3) == FP_STRING) + { + amx_Release(amx, allots[i-3].amx_addr); + } + } + return 1; }