From 582c3ec86e57fe9632a2c57f35815ad7bf6c593c Mon Sep 17 00:00:00 2001 From: wrv Date: Fri, 17 Nov 2023 11:46:50 -0600 Subject: [PATCH 1/2] Ignore example build files --- src/chapters/examples/noop-hello-example/.gitignore | 1 + src/chapters/examples/wasm-hello-example/.gitignore | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 src/chapters/examples/noop-hello-example/.gitignore create mode 100644 src/chapters/examples/wasm-hello-example/.gitignore 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/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 From b7d277ab65d52a2db9940480165f841721d2725a Mon Sep 17 00:00:00 2001 From: wrv Date: Fri, 17 Nov 2023 11:50:16 -0600 Subject: [PATCH 2/2] Add a crashing release_assert; remove old line in noop example --- src/chapters/examples/noop-hello-example/main.cpp | 7 +++---- src/chapters/examples/wasm-hello-example/main.cpp | 3 ++- src/chapters/noop-sandbox.md | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) 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/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); }); ```