Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

Fix three more defects a review of this branch found

RoversXcf21b4dbb7e4
diff --git a/PRIVACY.md b/PRIVACY.md
index 6190ab0a..11d91715 100644
--- a/PRIVACY.md
+++ b/PRIVACY.md
@@ -72,7 +72,10 @@ they take the permissions of the directory they land in, which for a
default user profile is you, SYSTEM and the Administrators group, and
nobody else. An administrator of the machine can therefore read them --
though an administrator can read the terminals themselves and does not
-need either file to do it.
+need either file to do it. That directory is the roaming half of the
+Windows profile: on a standalone machine it stays where it is, but on a
+domain that has roaming profiles turned on, Windows copies it to the
+profile server at sign-out, and both files go with it.
The first is the tokens, and only if a `token_file` is configured: unset
means memory only, and restarting the server forgets every token. What is
diff --git a/wezterm-gui/src/download.rs b/wezterm-gui/src/download.rs
index 7ef2076f..181b3ae3 100644
--- a/wezterm-gui/src/download.rs
+++ b/wezterm-gui/src/download.rs
@@ -12,7 +12,11 @@ fn neuter_name(name: &str) -> Option<&str> {
None => name,
};
- if name == "." || name == ".." {
+ // A name that ends in a separator, or was nothing to begin with, has
+ // no basename. Without this it came back as `Some("")`, which
+ // `download_dir.join("")` turned into the directory itself; creating
+ // that failed, and the retry loop then wrote the file as `.1`.
+ if name.is_empty() || name == "." || name == ".." {
return None;
}
@@ -95,6 +99,11 @@ mod tests {
assert_eq!(neuter_name("C:evil.txt"), None);
assert_eq!(neuter_name("."), None);
assert_eq!(neuter_name(".."), None);
+ // No basename at all falls through to the fallback name rather than
+ // to `Some("")`, which named the download directory itself.
+ assert_eq!(neuter_name(""), None);
+ assert_eq!(neuter_name("a/"), None);
+ assert_eq!(neuter_name("a\\"), None);
// Separators are cut, not refused -- both of them, on every
// platform, which is stricter than `Path::file_name` on unix.
assert_eq!(neuter_name("a/b/c.txt"), Some("c.txt"));
diff --git a/wezterm-gui/src/termwindow/remote_walk.rs b/wezterm-gui/src/termwindow/remote_walk.rs
index c86fdb9f..263133e9 100644
--- a/wezterm-gui/src/termwindow/remote_walk.rs
+++ b/wezterm-gui/src/termwindow/remote_walk.rs
@@ -162,11 +162,20 @@ fn windows_reserved_stem(name: &str) -> bool {
})
}
+/// The longest name these rules accept, in UTF-16 units. NTFS allows 255
+/// per component, but a name is never stored bare: a download lands as
+/// `name.part` first (`partial_download_path`) and, when the name is taken,
+/// as `name (n)` for `n` up to `DOWNLOAD_NAME_ATTEMPTS` -- and both suffixes
+/// have to fit within the same 255, or a name that passed here is refused
+/// by the filesystem a moment later. Twelve units covers ` (1000)` and
+/// `.part` together.
+const WINDOWS_NAME_LIMIT: usize = 255 - 12;
+
fn windows_download_name_is_valid(name: &str) -> bool {
!name.is_empty()
&& !matches!(name, "." | "..")
&& !name.ends_with([' ', '.'])
- && name.encode_utf16().count() <= 255
+ && name.encode_utf16().count() <= WINDOWS_NAME_LIMIT
&& !name.chars().any(windows_reserved_char)
&& !windows_reserved_stem(name)
}
@@ -200,13 +209,13 @@ fn windows_download_name(name: &str) -> Cow<'_, str> {
// which is exactly how the stem changes underneath: `CON` followed by
// 252 spaces is not a device name until the cut and the trim have taken
// the spaces away, and then it is.
- cut_to_255_utf16_units(&mut out);
+ cut_to_name_limit(&mut out);
if windows_reserved_stem(&out) {
out.insert(0, '_');
// The prefix can put it back over the limit. Cutting again is safe
// to do once: the stem now begins with `_`, so no amount of taking
// from the end can make it a device name a second time.
- cut_to_255_utf16_units(&mut out);
+ cut_to_name_limit(&mut out);
}
if out.is_empty() {
out.push_str("download");
@@ -214,14 +223,16 @@ fn windows_download_name(name: &str) -> Cow<'_, str> {
Cow::Owned(out)
}
-fn cut_to_255_utf16_units(name: &mut String) {
- if name.encode_utf16().count() <= 255 {
+/// Cut `name` to [`WINDOWS_NAME_LIMIT`] UTF-16 units on a character
+/// boundary, then trim what the cut may have exposed.
+fn cut_to_name_limit(name: &mut String) {
+ if name.encode_utf16().count() <= WINDOWS_NAME_LIMIT {
return;
}
let mut units = 0usize;
let mut end = name.len();
for (index, ch) in name.char_indices() {
- if units + ch.len_utf16() > 255 {
+ if units + ch.len_utf16() > WINDOWS_NAME_LIMIT {
end = index;
break;
}
@@ -718,6 +729,17 @@ mod tests {
name,
sanitized
);
+ // And it still fits once the download path has dressed it: a
+ // `.part` while it streams, ` (n)` when the name is taken. NTFS
+ // counts 255 UTF-16 units per component, and a name that only
+ // fits bare is refused by the filesystem a moment later.
+ let dressed = format!("{sanitized} (1000).part");
+ assert!(
+ dressed.encode_utf16().count() <= 255,
+ "sanitize({:?}) left no room for a suffix: {:?}",
+ name,
+ dressed
+ );
}
// A name that is already fine is handed back untouched, not copied.
assert!(matches!(
diff --git a/wezterm-gui/src/web_settings.rs b/wezterm-gui/src/web_settings.rs
index 17495143..25470aa0 100644
--- a/wezterm-gui/src/web_settings.rs
+++ b/wezterm-gui/src/web_settings.rs
@@ -309,6 +309,19 @@ pub fn restart(window: Window, bind_address: String) {
return;
};
promise::spawn::spawn_into_main_thread(async move {
+ // Off and on are two requests, and the second can be refused after
+ // the first has already succeeded: the server will not open a
+ // non-loopback listener for a client that reached it over TLS, and
+ // any address can fail to bind. Either would leave the listener off
+ // with nothing to say so. What was listening is asked for first, so
+ // a refused "on" puts it back before the error is shown.
+ let before = match client.get_web_server_status().await {
+ Ok(status) => status.listening,
+ Err(err) => {
+ finish(&window, Some(format!("{err:#}")), Gate::Action);
+ return;
+ }
+ };
let off = client
.set_web_server(codec::SetWebServer { enabled: false, bind_address: None })
.await;
@@ -327,7 +340,23 @@ pub fn restart(window: Window, bind_address: String) {
finish(&window, None, Gate::Action);
refresh(window);
}
- Err(err) => finish(&window, Some(format!("{err:#}")), Gate::Action),
+ Err(err) => {
+ let mut restored = Ok(());
+ for address in before {
+ let put_back = client
+ .set_web_server(codec::SetWebServer { enabled: true, bind_address: Some(address) })
+ .await;
+ if let Err(err) = put_back {
+ restored = Err(err);
+ }
+ }
+ let message = match restored {
+ Ok(()) => format!("{err:#}"),
+ Err(restore_err) => format!("{err:#}; and putting the previous listener back failed: {restore_err:#}"),
+ };
+ finish(&window, Some(message), Gate::Action);
+ refresh(window);
+ }
}
})
.detach();