mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
clean up hook/cbak type detection
This commit is contained in:
@@ -127,6 +127,7 @@ namespace hook
|
|||||||
WASM_TOO_BIG = 79, // set hook would exceed maximum hook size
|
WASM_TOO_BIG = 79, // set hook would exceed maximum hook size
|
||||||
WASM_TOO_SMALL = 80,
|
WASM_TOO_SMALL = 80,
|
||||||
WASM_VALIDATION = 81, // a generic error while parsing wasm, usually leb128 overflow
|
WASM_VALIDATION = 81, // a generic error while parsing wasm, usually leb128 overflow
|
||||||
|
HOOK_CBAK_DIFF_TYPES = 82, // hook and cbak function definitions were different
|
||||||
// RH NOTE: only HookSet msgs got log codes, possibly all Hook log lines should get a code?
|
// RH NOTE: only HookSet msgs got log codes, possibly all Hook log lines should get a code?
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -754,13 +754,24 @@ validateGuards(
|
|||||||
int hook_type_idx = func_type_map[*hook_func_idx];
|
int hook_type_idx = func_type_map[*hook_func_idx];
|
||||||
|
|
||||||
// cbak function is optional so if it exists it has a type otherwise it is skipped in checks
|
// cbak function is optional so if it exists it has a type otherwise it is skipped in checks
|
||||||
std::optional<int> cbak_type_idx;
|
if (cbak_func_idx && func_type_map[*cbak_func_idx] != hook_type_idx)
|
||||||
if (cbak_func_idx)
|
{
|
||||||
cbak_type_idx = func_type_map[*cbak_func_idx];
|
GUARDLOG(hook::log::HOOK_CBAK_DIFF_TYPES)
|
||||||
|
<< "Malformed transaction. "
|
||||||
|
<< "Hook and cbak func must have the same type. int64_t (*)(uint32_t).\n";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
int64_t maxInstrCountHook = 0;
|
int64_t maxInstrCountHook = 0;
|
||||||
int64_t maxInstrCountCbak = 0;
|
int64_t maxInstrCountCbak = 0;
|
||||||
|
|
||||||
|
/* printf( "hook_func_idx: %d\ncbak_func_idx: %d\n"
|
||||||
|
"hook_type_idx: %d\ncbak_type_idx: %d\n",
|
||||||
|
*hook_func_idx,
|
||||||
|
*cbak_func_idx,
|
||||||
|
hook_type_idx, *cbak_type_idx);
|
||||||
|
*/
|
||||||
|
|
||||||
// second pass... where we check all the guard function calls follow the guard rules
|
// second pass... where we check all the guard function calls follow the guard rules
|
||||||
// minimal other validation in this pass because first pass caught most of it
|
// minimal other validation in this pass because first pass caught most of it
|
||||||
for (int i = 8; i < hook.size();)
|
for (int i = 8; i < hook.size();)
|
||||||
@@ -788,11 +799,19 @@ validateGuards(
|
|||||||
CHECK_SHORT_HOOK();
|
CHECK_SHORT_HOOK();
|
||||||
|
|
||||||
int param_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
|
int param_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
|
||||||
|
if (j == hook_type_idx && param_count != 1)
|
||||||
|
{
|
||||||
|
GUARDLOG(hook::log::PARAM_HOOK_CBAK)
|
||||||
|
<< "Malformed transaction. "
|
||||||
|
<< "hook and cbak function definition must have exactly one parameter (uint32_t)." << "\n";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
for (int k = 0; k < param_count; ++k)
|
for (int k = 0; k < param_count; ++k)
|
||||||
{
|
{
|
||||||
int param_type = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
|
int param_type = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
|
||||||
if (param_type == 0x7F || param_type == 0x7E ||
|
if (param_type == 0x7FU || param_type == 0x7EU ||
|
||||||
param_type == 0x7D || param_type == 0x7C)
|
param_type == 0x7DU || param_type == 0x7CU)
|
||||||
{
|
{
|
||||||
// pass, this is fine
|
// pass, this is fine
|
||||||
}
|
}
|
||||||
@@ -812,8 +831,7 @@ validateGuards(
|
|||||||
j, *hook_func_idx, *cbak_func_idx, param_count, param_type);
|
j, *hook_func_idx, *cbak_func_idx, param_count, param_type);
|
||||||
|
|
||||||
// hook and cbak parameter check here
|
// hook and cbak parameter check here
|
||||||
if ((j == hook_type_idx || (cbak_type_idx && j == cbak_type_idx)) &&
|
if (j == hook_type_idx && param_type != 0x7FU /* i32 */)
|
||||||
(param_count != 1 || param_type != 0x7F /* i32 */ ))
|
|
||||||
{
|
{
|
||||||
GUARDLOG(hook::log::PARAM_HOOK_CBAK)
|
GUARDLOG(hook::log::PARAM_HOOK_CBAK)
|
||||||
<< "Malformed transaction. "
|
<< "Malformed transaction. "
|
||||||
@@ -860,8 +878,7 @@ validateGuards(
|
|||||||
j, *hook_func_idx, *cbak_func_idx, result_count, result_type);
|
j, *hook_func_idx, *cbak_func_idx, result_count, result_type);
|
||||||
|
|
||||||
// hook and cbak return type check here
|
// hook and cbak return type check here
|
||||||
if ((j == hook_type_idx || (cbak_type_idx && j == cbak_type_idx)) &&
|
if (j == hook_type_idx && (result_count != 1 || result_type != 0x7E /* i64 */))
|
||||||
(result_count != 1 || result_type != 0x7E /* i64 */ ))
|
|
||||||
{
|
{
|
||||||
GUARDLOG(hook::log::RETURN_HOOK_CBAK)
|
GUARDLOG(hook::log::RETURN_HOOK_CBAK)
|
||||||
<< "Malformed transaction. "
|
<< "Malformed transaction. "
|
||||||
|
|||||||
Reference in New Issue
Block a user