diff options
Diffstat (limited to 'src/env.c')
| -rw-r--r-- | src/env.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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); |
