Skip to content

Commit

Permalink
fix SAMPNode_CallEvent crash by adding an offset
Browse files Browse the repository at this point in the history
  • Loading branch information
AmyrAhmady committed May 1, 2020
1 parent 09e06a2 commit 979b6d0
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ namespace sampnode
v8::Local<v8::Value>* argv = NULL;
unsigned int argc = paramTypes.length();
argv = new v8::Local<v8::Value>[argc];
int paramOffset = 0;

for (unsigned int i = 0; i < argc; i++)
{
Expand All @@ -380,7 +381,7 @@ namespace sampnode
cell* maddr = NULL;
int len = 0;
char* sval;
if (amx_GetAddr(amx, params[i + 1], &maddr) != AMX_ERR_NONE)
if (amx_GetAddr(amx, params[i + paramOffset + 1], &maddr) != AMX_ERR_NONE)
{
L_ERROR << "Can't get string address: " << name.c_str();
return;
Expand All @@ -398,53 +399,53 @@ namespace sampnode
case 'a':
{
cell* array = NULL;
if (amx_GetAddr(amx, params[i + 1], &array) != AMX_ERR_NONE)
if (amx_GetAddr(amx, params[i + paramOffset + 1], &array) != AMX_ERR_NONE)
{
L_ERROR << "Can't get array address: " << name.c_str();
return;
}
int size = static_cast<int>(*utils::get_amxaddr(amx, params[i + 2]));
int size = static_cast<int>(*utils::get_amxaddr(amx, params[i + paramOffset + 2]));
v8::Local<v8::Array> jsArray = v8::Array::New(isolate, size);
for (int j = 0; j < size; j++)
{
jsArray->Set(j, v8::Integer::New(isolate, static_cast<uint32_t>(array[j])));
}
argv[i] = jsArray;
i++;
paramOffset++;
break;
}
case 'v':
{
cell* array = NULL;
if (amx_GetAddr(amx, params[i + 1], &array) != AMX_ERR_NONE)
if (amx_GetAddr(amx, params[i + paramOffset + 1], &array) != AMX_ERR_NONE)
{
L_ERROR << "Can't get float array address: " << name.c_str();
return;
}

int size = static_cast<int>(*utils::get_amxaddr(amx, params[i + 2]));
int size = static_cast<int>(*utils::get_amxaddr(amx, params[i + paramOffset + 2]));
v8::Local<v8::Array> jsArray = v8::Array::New(isolate, size);
for (int j = 0; j < size; j++)
{
jsArray->Set(j, v8::Integer::New(isolate, amx_ctof(array[j])));
}
argv[i] = jsArray;
i++;
paramOffset++;
break;
}
case 'd':
{
argv[i] = v8::Integer::New(isolate, static_cast<int32_t>(*utils::get_amxaddr(amx, params[i + 1])));
argv[i] = v8::Integer::New(isolate, static_cast<int32_t>(*utils::get_amxaddr(amx, params[i + paramOffset + 1])));
break;
}
case 'i':
{
argv[i] = v8::Integer::New(isolate, static_cast<uint32_t>(*utils::get_amxaddr(amx, params[i + 1])));
argv[i] = v8::Integer::New(isolate, static_cast<uint32_t>(*utils::get_amxaddr(amx, params[i + paramOffset + 1])));
break;
}
case 'f':
{
argv[i] = v8::Number::New(isolate, amx_ctof(*utils::get_amxaddr(amx, params[i + 1])));
argv[i] = v8::Number::New(isolate, amx_ctof(*utils::get_amxaddr(amx, params[i + paramOffset + 1])));
break;
}
}
Expand Down

0 comments on commit 979b6d0

Please sign in to comment.