mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2024-11-26 15:32:05 +00:00
Attestation: Free JSON from the Wasm module heap (#2803)
The JSON evidence is allocated on the module instance heap, but no API was given to dispose of this memory buffer. The sample mentions using the function free, which behaves differently depending on the execution context. This fix provides a new function called librats_dispose_evidence_json, enabling freeing the JSON evidence directly from the Wasm app.
This commit is contained in:
parent
4d5eb346fc
commit
f9e8b9535e
|
@ -17,7 +17,7 @@
|
|||
#include "lib_rats_common.h"
|
||||
|
||||
static int
|
||||
librats_collect_wrapper(wasm_exec_env_t exec_env, char **evidence_json,
|
||||
librats_collect_wrapper(wasm_exec_env_t exec_env, uint32_t *evidence_json,
|
||||
const char *buffer, uint32_t buffer_size)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
|
@ -47,7 +47,7 @@ librats_collect_wrapper(wasm_exec_env_t exec_env, char **evidence_json,
|
|||
return (int)RATS_ATTESTER_ERR_NO_MEM;
|
||||
}
|
||||
bh_memcpy_s(str_ret, json_size, json, json_size);
|
||||
*((int *)evidence_json) = str_ret_offset;
|
||||
*evidence_json = str_ret_offset;
|
||||
free(json);
|
||||
|
||||
return 0;
|
||||
|
@ -96,6 +96,15 @@ librats_parse_evidence_wrapper(wasm_exec_env_t exec_env,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
librats_dispose_evidence_json_wrapper(wasm_exec_env_t exec_env,
|
||||
uint32_t evidence_json)
|
||||
{
|
||||
wasm_module_inst_t module_inst = get_module_inst(exec_env);
|
||||
|
||||
module_free(evidence_json);
|
||||
}
|
||||
|
||||
/* clang-format off */
|
||||
#define REG_NATIVE_FUNC(func_name, signature) \
|
||||
{ #func_name, func_name##_wrapper, signature, NULL }
|
||||
|
@ -104,7 +113,8 @@ librats_parse_evidence_wrapper(wasm_exec_env_t exec_env,
|
|||
static NativeSymbol native_symbols_lib_rats[] = {
|
||||
REG_NATIVE_FUNC(librats_collect, "(**~)i"),
|
||||
REG_NATIVE_FUNC(librats_verify, "(*~*~)i"),
|
||||
REG_NATIVE_FUNC(librats_parse_evidence, "(*~*~)i")
|
||||
REG_NATIVE_FUNC(librats_parse_evidence, "(*~*~)i"),
|
||||
REG_NATIVE_FUNC(librats_dispose_evidence_json, "(i)")
|
||||
};
|
||||
|
||||
uint32_t
|
||||
|
|
|
@ -41,6 +41,9 @@ librats_parse_evidence(const char *evidence_json, uint32_t json_size,
|
|||
evidence_json ? strlen(evidence_json) + 1 : 0, \
|
||||
evidence, sizeof(rats_sgx_evidence_t))
|
||||
|
||||
void
|
||||
librats_dispose_evidence_json(char *evidence_json);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -106,7 +106,7 @@ main(int argc, char **argv)
|
|||
|
||||
err:
|
||||
if (evidence_json) {
|
||||
free(evidence_json);
|
||||
librats_dispose_evidence_json(evidence_json);
|
||||
}
|
||||
|
||||
if (evidence) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user