aboutsummaryrefslogtreecommitdiff
path: root/src/env.c
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-10-29 13:22:28 +0100
committerNicholas Rodrigues Lordello <[email protected]>2026-10-29 13:33:26 +0100
commit838d75bce98ca5a1f90f762e80d2aa649d4e0642 (patch)
tree06d661dd944d80632aa80a9f605a679779575dc5 /src/env.c
parente51027a576a07ffb41b6e7d2bfc3aade6ae091d7 (diff)
Minor Fixes
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/env.c b/src/env.c
index 9a41eb6..5f03bb2 100644
--- a/src/env.c
+++ b/src/env.c
@@ -729,11 +729,17 @@ uint32_t w2c_env_0x5F_0x5Fsyscall146(struct w2c_env *env, uint32_t which,
for (uint32_t i = 0; i < iovcnt; i++) {
uint32_t buffer = wasm_rt_memory_load32(&env->memory, iov + 8 * i);
uint32_t len = wasm_rt_memory_load32(&env->memory, iov + 8 * i + 4);
+
+ // Make sure to check the source range before writing, this ensures that
+ // we don't modify the storage file-system when we would trap anyway,
+ // leaving it in a bad state.
+ wasm_rt_memory_check(&env->memory, buffer, len);
+
uint8_t *contents = pw_fs_write(env->context.cart->storage, fd, len);
if (!contents) {
return -pw_fs_errno(env->context.cart->storage);
}
- wasm_rt_memory_load(&env->memory, buffer, contents, len);
+ wasm_rt_memory_load_unchecked(&env->memory, buffer, contents, len);
}
if (!pw_fs_flush(env->context.cart->storage, fd)) {
@@ -763,6 +769,7 @@ uint32_t w2c_env_0x5F_0x5Fsyscall195(struct w2c_env *env, uint32_t which,
// of the fields. If ever this causes issues with PICO-8 things (which I
// have not noticed for any cart), we can implement something.
+ wasm_rt_memory_check(&env->memory, stat, 88);
MEM_WRITE(32, env, stat, 0); // st_dev
MEM_WRITE(64, env, stat, 0); // st_ino
MEM_WRITE(32, env, stat, s.mode);