mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
wasm: emit unreachable instruction after opa_abort() (#3574)
It's become apparent that a call to opa_abort in opa_agg_count did NOT stop execution. Failures in bad input there haven't been thoroughly tested. Comparing to the calls to opa_abort that happen in compiler-emitted code (as opposed to calls in the C portion of our wasm code base), we find that they are always emitting `unreachable` after the call to opa_abort. As it turns out, doing the same thing in the C parts fixes the problem. It thus seems like this is somehow related to changes in wasmtime's cranelift (or its backend). It's never wrong to give the compiler some more information that we can readily share, so let's put some `unreachable` into the their proper places. To avoid touching the entire code base of the C parts, we're defining a function called `opa_abort(msg)` that'll call `opa_abort_(msg)` followed by `__builtin_unreachable()`, which gives us that instruction. `opa_abort_` in turn is imported as `opa_abort`, to keep compatibility with any SDKs out there. Signed-off-by: Stephan Renatus <stephan.renatus@gmail.com>
This commit is contained in:
@@ -225,6 +225,13 @@ a = "c" { input > 2 }`,
|
||||
{Result: `{{}}`},
|
||||
},
|
||||
},
|
||||
{
|
||||
Description: "Runtime error/bad utf8 input to count()",
|
||||
Policy: `a = count(base64.decode("2E84ZuPUd7zfvCZSNEchVpDEIj6PL7JfLpIqyxVG16k="))`,
|
||||
Query: "data.p.a = x",
|
||||
Evals: []Eval{{}},
|
||||
WantErr: "internal_error: string: invalid unicode",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "str.h"
|
||||
#include "value.h"
|
||||
#include "json.h"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "printf.h"
|
||||
|
||||
#include "../std.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
struct _FILE {};
|
||||
|
||||
|
||||
@@ -15,6 +15,12 @@ void abort(void)
|
||||
}
|
||||
}
|
||||
|
||||
void opa_abort(const char *msg)
|
||||
{
|
||||
opa_abort_(msg);
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
void *malloc(size_t size)
|
||||
{
|
||||
return opa_malloc(size);
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void opa_abort(const char *msg);
|
||||
__attribute__((import_name("opa_abort"))) void opa_abort_(const char *msg);
|
||||
void abort(void);
|
||||
void *malloc(size_t size);
|
||||
void free(void *ptr);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include <string.h>
|
||||
#include "std.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
#define WASM_PAGE_SIZE (65536)
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ extern "C" {
|
||||
#define container_of(ptr, type, member) \
|
||||
((type *)(void *)( ((char *)(ptr) - offsetof(type, member) )))
|
||||
|
||||
void opa_abort(const char *msg);
|
||||
void opa_println(const char *msg);
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
opa_abort
|
||||
opa_println
|
||||
opa_builtin0
|
||||
opa_builtin1
|
||||
|
||||
Reference in New Issue
Block a user