diff options
author | Aram Drevekenin <aram@poor.dev> | 2024-02-09 16:39:37 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-09 16:39:37 +0100 |
commit | fffeca3e6eeea379d74e294b3626f4823945bc5c (patch) | |
tree | 5d657d8b70ca82ef8a08ea978c4344ca25b9aae9 | |
parent | e828e277c20c8346607ef5ffba09f2944abbe237 (diff) |
fix(plugins): crash when reattaching to a non-existent host folder (#3126)
-rw-r--r-- | zellij-server/src/plugins/plugin_loader.rs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/zellij-server/src/plugins/plugin_loader.rs b/zellij-server/src/plugins/plugin_loader.rs index c14a324b7..b74c80b18 100644 --- a/zellij-server/src/plugins/plugin_loader.rs +++ b/zellij-server/src/plugins/plugin_loader.rs @@ -795,11 +795,22 @@ impl<'a> PluginLoader<'a> { }; let mut store = get_store(); let store_mut = &mut store; + let dirs = vec![ + ("/host".to_owned(), self.zellij_cwd.clone()), + ("/data".to_owned(), self.plugin_own_data_dir.clone()), + ("/tmp".to_owned(), ZELLIJ_TMP_DIR.clone()), + ]; + let dirs = dirs.into_iter().filter(|(_dir_name, dir)| { + // note that this does not protect against TOCTOU errors + // eg. if one or more of these folders existed at the time of check but was deleted + // before we mounted in in the wasi environment, we'll crash + // when we move to a new wasi environment, we should address this with locking if + // there's no built-in solution + dir.try_exists().ok().unwrap_or(false) + }); let mut wasi_env = WasiState::new("Zellij") .env("CLICOLOR_FORCE", "1") - .map_dir("/host", self.zellij_cwd.clone()) - .and_then(|wasi| wasi.map_dir("/data", &self.plugin_own_data_dir)) - .and_then(|wasi| wasi.map_dir("/tmp", ZELLIJ_TMP_DIR.as_path())) + .map_dirs(dirs) .and_then(|wasi| { wasi.stdin(Box::new(Pipe::new())) .stdout(Box::new(Pipe::new())) |