diff --git a/src/chapters/examples/noop-hello-example/.gitignore b/src/chapters/examples/noop-hello-example/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/src/chapters/examples/noop-hello-example/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/src/chapters/examples/noop-hello-example/main.cpp b/src/chapters/examples/noop-hello-example/main.cpp index 7e704e0..c9ce15c 100644 --- a/src/chapters/examples/noop-hello-example/main.cpp +++ b/src/chapters/examples/noop-hello-example/main.cpp @@ -9,6 +9,8 @@ #include #include +#define release_assert(cond, msg) if (!(cond)) { fputs(msg, stderr); abort(); } + #include "mylib.h" using namespace std; @@ -33,9 +35,6 @@ int main(int argc, char const *argv[]) { // ANCHOR: add // call the add function and check the result: - auto val = sandbox.invoke_sandbox_function(add, 3, 4); - printf("Adding... 3+4 = %d\n", val); - auto ok = sandbox.invoke_sandbox_function(add, 3, 4) .copy_and_verify([](unsigned ret){ printf("Adding... 3+4 = %d\n", ret); @@ -76,7 +75,7 @@ int main(int argc, char const *argv[]) { void hello_cb(rlbox_sandbox_mylib& _, tainted_mylib str) { auto checked_string = str.copy_and_verify_string([](unique_ptr val) { - assert(val != nullptr && strlen(val.get()) < 1024); + release_assert(val != nullptr && strlen(val.get()) < 1024, "val is null or greater than 1024\n"); return move(val); }); printf("hello_cb: %s\n", checked_string.get()); diff --git a/src/chapters/examples/wasm-hello-example/.gitignore b/src/chapters/examples/wasm-hello-example/.gitignore new file mode 100644 index 0000000..1c6adc6 --- /dev/null +++ b/src/chapters/examples/wasm-hello-example/.gitignore @@ -0,0 +1,3 @@ +myapp +mylib.wasm* +wasm* \ No newline at end of file diff --git a/src/chapters/examples/wasm-hello-example/main.cpp b/src/chapters/examples/wasm-hello-example/main.cpp index 8d8abd4..43f46ac 100644 --- a/src/chapters/examples/wasm-hello-example/main.cpp +++ b/src/chapters/examples/wasm-hello-example/main.cpp @@ -15,6 +15,7 @@ #include "rlbox.hpp" #include "rlbox_wasm2c_sandbox.hpp" +#define release_assert(cond, msg) if (!(cond)) { fputs(msg, stderr); abort(); } using namespace std; using namespace rlbox; @@ -78,7 +79,7 @@ int main(int argc, char const *argv[]) { void hello_cb(rlbox_sandbox_mylib& _, tainted_mylib str) { auto checked_string = str.copy_and_verify_string([](unique_ptr val) { - assert(val != nullptr && strlen(val.get()) < 1024); + release_assert(val != nullptr && strlen(val.get()) < 1024); return move(val); }); printf("hello_cb: %s\n", checked_string.get()); diff --git a/src/chapters/noop-sandbox.md b/src/chapters/noop-sandbox.md index 843156a..6a9c02c 100644 --- a/src/chapters/noop-sandbox.md +++ b/src/chapters/noop-sandbox.md @@ -167,7 +167,7 @@ string we need to verify it. To do this, we use the string verification function ```cpp str.copy_and_verify_string([](unique_ptr val) { - assert(val != nullptr && strlen(val.get()) < 1024); + release_assert(val != nullptr && strlen(val.get()) < 1024, "val is null or greater than 1024\n"); return move(val); }); ```