Commit Graph

13362 Commits

Author SHA1 Message Date
Michael Hazan
6dd9a74e6e fix(docs): window-decoration is now none instead of false 2025-12-12 22:56:06 +02:00
Mitchell Hashimoto
c198c6dc69 fix: bash shell integration use-after-free bug from PR #9881 (#9885)
(Claude-generated content below)

## Fix bash shell integration use-after-free bug

### Problem

After updating to the latest `main` branch, Ghostty fails to launch with
bash shell integration enabled on Linux (Ubuntu 25.10). The terminal
window briefly appears and then closes with an error like:

```
/bin/sh: 1: ically: not found
```

The error message varies but typically contains fragments of words (like
"ically" from "automatically").

Related issue was possibly [reported in the comments of PR
#9881](https://github.com/ghostty-org/ghostty/pull/9881) shortly after
it was merged.

### Root Cause Analysis

The bug is a **use-after-free** in the bash shell integration setup.

In `setupBash()`, the `ShellCommandBuilder` is initialized with a
`stackFallback` allocator:

```zig
var stack_fallback = std.heap.stackFallback(4096, alloc);
var cmd = internal_os.shell.ShellCommandBuilder.init(stack_fallback.get());
```

When `cmd.toOwnedSlice()` is called, it returns a slice allocated from
the `stackFallback` allocator. Since the command string (e.g., "bash
--posix") easily fits within 4096 bytes, this memory is allocated on the
**stack**.

When `setupBash()` returns, the stack frame is deallocated, but the
returned `.shell` command still points to this now-invalid stack memory.
When the command is later used in `execCommand()` to build the `/bin/sh
-c "..."` invocation, it reads garbage data.

The garbage data often contains "ically" because it picks up fragments
from nearby memory—likely from the string literal "automatically" in the
comment on line 280:

```zig
// being manually sourced or automatically injected (from here).
```

This is a [known footgun with Zig's stackFallback
allocator](https://github.com/ziglang/zig/issues/16344) - memory
allocated from the stack portion becomes invalid once the stack frame is
exited.

### Bisect / Blame

The bug was introduced **~5 hours ago** (earlier today):

| Field | Value |
|-------|-------|
| **Commit** | `04fecd7c07fccad423ab1c33324a1997e142b6e2` |
| **PR** | [#9881](https://github.com/ghostty-org/ghostty/pull/9881)
(os/shell: introduce ShellCommandBuilder) |
| **Date** | Fri Dec 12 08:59:44 2025 -0500 |
| **Merged as** | `dd06d8a13` |

The previous implementation in commit `c0deaaba4` used
`std.mem.joinZ(alloc, " ", args.items)` which correctly allocated the
result using the arena allocator. The refactor to use
`ShellCommandBuilder` inadvertently changed the allocation strategy to
use stack memory for the returned value.

Other uses of `stackFallback` in the codebase are safe because they
either:
- Copy data to another allocator before the function returns (e.g.,
`env.put()` in `setupXdgDataDirs`)
- Use the data only within the function scope (e.g.,
`stream_handler.zig`)

### The Fix

Copy the command string to the arena allocator before returning:

```zig
const cmd_str = try cmd.toOwnedSlice();
return .{ .shell = try alloc.dupeZ(u8, cmd_str) };
```

This ensures the memory remains valid for the lifetime needed by the
caller, matching the behavior of other `stackFallback` usage patterns in
the codebase.

### Testing

- Verified the fix on Ubuntu 25.10 with Ghostty built from source
- Before fix: Terminal crashes immediately with "ically: not found"
error
- After fix: Terminal launches successfully with shell integration
working

```
info(io_exec): shell integration automatically injected shell=.bash
info(io_exec): started subcommand path=/bin/sh pid=...
info(surface): surface closed addr=...  # Normal close, no "abnormal process exit"
```

### Platform

Primarily affects Linux where `.shell` commands are wrapped in `/bin/sh
-c "..."`. macOS uses a different execution path via `login(1)`.
2025-12-12 12:11:06 -08:00
Michael Bommarito
2d9c83dbb7 fix: bash shell integration use-after-free bug
The ShellCommandBuilder uses a stackFallback allocator, which means
toOwnedSlice() may return memory allocated on the stack. When setupBash()
returns, this stack memory becomes invalid, causing a use-after-free.

This manifested as garbage data in the shell command string, often
appearing as errors like "/bin/sh: 1: ically: not found" (where "ically"
was part of nearby memory, likely from the comment "automatically").

The fix copies the command string to the arena allocator before returning,
ensuring the memory remains valid for the lifetime of the command.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-12 13:36:36 -05:00
Mitchell Hashimoto
dd06d8a13b os/shell: introduce ShellCommandBuilder (#9881)
This builder is an efficient way to construct space-separated shell
command strings.

We use it in setupBash to avoid using an intermediate array of arguments
to construct our bash command line.
2025-12-12 07:09:58 -08:00
Mitchell Hashimoto
c95801db85 CONTRIBUTING: limit AI assistance to code only (#9882)
I think at this point all moderators and helpers can agree with me in
that LLM-generated responses are a blight upon this Earth.

Also probably worth putting in a clause against AI-generated assets
2025-12-12 07:09:35 -08:00
Jon Parise
04fecd7c07 os/shell: introduce ShellCommandBuilder
This builder is an efficient way to construct space-separated shell
command strings.

We use it in setupBash to avoid using an intermediate array of arguments
to construct our bash command line.
2025-12-12 08:59:44 -05:00
Leah Amelia Chen
315c8852a8 CONTRIBUTING: reorganize paragraphs 2025-12-12 18:59:22 +08:00
Leah Amelia Chen
8a1bb215c1 CONTRIBUTING: further clarifications 2025-12-12 18:56:24 +08:00
Leah Amelia Chen
5e049e1b3a CONTRIBUTING: AI-assisted != AI-generated 2025-12-12 18:53:10 +08:00
Leah Amelia Chen
65539d0d54 CONTRIBUTING: limit AI assistance to code only
I think at this point all moderators and helpers can agree with me in
that LLM-generated responses are a blight upon this Earth.

Also probably worth putting in a clause against AI-generated assets
(cf. the Commit Goods situation)
2025-12-12 18:43:51 +08:00
Mitchell Hashimoto
5aefb4b0a8 build(deps): bump cachix/install-nix-action from 31.8.4 to 31.9.0 (#9877)
Bumps
[cachix/install-nix-action](https://github.com/cachix/install-nix-action)
from 31.8.4 to 31.9.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/cachix/install-nix-action/releases">cachix/install-nix-action's
releases</a>.</em></p>
<blockquote>
<h2>v31.9.0</h2>
<h2>What's Changed</h2>
<ul>
<li>nix: 2.32.4 -&gt; 2.33.0 by <a
href="https://github.com/github-actions"><code>@​github-actions</code></a>[bot]
in <a
href="https://redirect.github.com/cachix/install-nix-action/pull/264">cachix/install-nix-action#264</a></li>
<li>chore(deps): bump peter-evans/create-pull-request from 7 to 8 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a>[bot]
in <a
href="https://redirect.github.com/cachix/install-nix-action/pull/263">cachix/install-nix-action#263</a></li>
<li>chore(deps): bump actions/checkout from 5 to 6 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a>[bot]
in <a
href="https://redirect.github.com/cachix/install-nix-action/pull/262">cachix/install-nix-action#262</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/cachix/install-nix-action/compare/v31.8.4...v31.9.0">https://github.com/cachix/install-nix-action/compare/v31.8.4...v31.9.0</a></p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4e002c8ec8"><code>4e002c8</code></a>
Merge pull request <a
href="https://redirect.github.com/cachix/install-nix-action/issues/262">#262</a>
from cachix/dependabot/github_actions/actions/checkout-6</li>
<li><a
href="65fe36965b"><code>65fe369</code></a>
Merge pull request <a
href="https://redirect.github.com/cachix/install-nix-action/issues/263">#263</a>
from cachix/dependabot/github_actions/peter-evans/cre...</li>
<li><a
href="c61d28fbcf"><code>c61d28f</code></a>
Merge pull request <a
href="https://redirect.github.com/cachix/install-nix-action/issues/264">#264</a>
from cachix/create-pull-request/patch</li>
<li><a
href="72e7d4072f"><code>72e7d40</code></a>
nix: 2.32.4 -&gt; 2.33.0</li>
<li><a
href="15a7ab2c66"><code>15a7ab2</code></a>
chore(deps): bump peter-evans/create-pull-request from 7 to 8</li>
<li><a
href="523410fd45"><code>523410f</code></a>
chore(deps): bump actions/checkout from 5 to 6</li>
<li><a
href="7e5978947b"><code>7e59789</code></a>
ci: drop macos-13 runner</li>
<li>See full diff in <a
href="0b0e072294...4e002c8ec8">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=cachix/install-nix-action&package-manager=github_actions&previous-version=31.8.4&new-version=31.9.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>
2025-12-11 16:54:02 -08:00
Mitchell Hashimoto
cba82e976c macOS: Change Tab Title (#9879)
This adds the ability to change a _tab_ title. The previous
functionality was tied to a specific _surface_. A tab title will stick
to the current tab regardless of active splits and so on.

This follows the nomenclature that macOS terminal app does which is
"title vs terminal title" (although we explicitly use "tab" in various
places, I may remove that in the future).

**This is macOS only. GTK is tracked here: #9880**. I did macOS only
because thats the machine I'm on. It'll be trivial to add this to GTK,
too.

## Demo


https://github.com/user-attachments/assets/d9446785-d919-4212-8553-db50c56c8c2f

(The option is also in the main menu, the context menu, and the command
palette)

## AI Disclosure

This PR was done fully with Amp, I didn't write a single line of code at
the time of writing this PR description. I reviewed everything though
and fully understand it all. Its a mimic more or less of the prompt
surface title work (although we did unify some stuff like the apprt
action).
2025-12-11 16:53:50 -08:00
Mitchell Hashimoto
50bbced0c9 macos: add title override to restorable state 2025-12-11 16:40:09 -08:00
Mitchell Hashimoto
6105344c31 macos: add change tab title to right click menu 2025-12-11 16:30:06 -08:00
Mitchell Hashimoto
65c5e72d3e macos: add tab title change to tab context menu 2025-12-11 16:24:50 -08:00
Mitchell Hashimoto
7b48eb5c62 macos: add change tab title to menu 2025-12-11 16:16:12 -08:00
Mitchell Hashimoto
65cf124e2c core: change apprt action to enum value instead of a new one 2025-12-11 16:09:45 -08:00
dependabot[bot]
1f05625d3f build(deps): bump cachix/install-nix-action from 31.8.4 to 31.9.0
Bumps [cachix/install-nix-action](https://github.com/cachix/install-nix-action) from 31.8.4 to 31.9.0.
- [Release notes](https://github.com/cachix/install-nix-action/releases)
- [Changelog](https://github.com/cachix/install-nix-action/blob/master/RELEASE.md)
- [Commits](0b0e072294...4e002c8ec8)

---
updated-dependencies:
- dependency-name: cachix/install-nix-action
  dependency-version: 31.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-12-12 00:06:57 +00:00
Mitchell Hashimoto
e93a4a911f macos: implement prompt_tab_title 2025-12-11 16:03:30 -08:00
Mitchell Hashimoto
32033c9e1a core: prompt_tab_title binding and apprt action 2025-12-11 16:03:19 -08:00
Mitchell Hashimoto
2448a90c30 bash: use a shell command for shell integration (#9875)
Prior to #7044, on macOS, our shell-integrated command line would be
executed under `exec -l`, which causes bash to be started as a login
shell. This matches the macOS platform norms.

The change to direct command execution meant that we'd skip that path,
and bash would start as a normal interactive (non-login) shell on macOS.
We fixed this in #7253 by adding `--login` to the `bash` direct command
on macOS.

This avoided some of the overhead of starting an extra process just to
get a login shell, but it unfortunately doesn't quite match the bash
environment we get when shell integration isn't enabled (namely, `$0`
doesn't get the login-shell-identifying `-` prefix).

Instead, this change implements the approach proposed in #7254, which
switches the bash shell integration path to use a `.shell` command,
giving us the same execution environment as the non-shell-integrated
command.
2025-12-11 15:41:29 -08:00
Mitchell Hashimoto
4d757f0f28 macos: show tab color as header for menu item so its not grey 2025-12-11 14:43:26 -08:00
Mitchell Hashimoto
89bdee447f macos: selected color in tab color menu should use target's color 2025-12-11 14:33:50 -08:00
Mitchell Hashimoto
d77b7c32f9 feat(macos): add tab color picker to tab context menu (#9784)
<img width="1824" height="1488" alt="image"
src="https://github.com/user-attachments/assets/4a77f743-9eae-40bf-8cb4-d45d884a85a5"
/>
2025-12-11 14:27:25 -08:00
Mitchell Hashimoto
2331e17835 macos: change tab color label to circle 2025-12-11 14:18:57 -08:00
Jon Parise
c0deaaba4e bash: use a shell command for shell integration
Prior to #7044, on macOS, our shell-integrated command line would be
executed under exec -l, which causes bash to be started as a login
shell. This matches the macOS platform norms.

The change to direct command execution meant that we'd skip that path,
and bash would start as a normal interactive (non-login) shell on macOS.
We fixed this in #7253 by adding `--login` to the `bash` direct command
on macOS.

This avoided some of the overhead of starting an extra process just to
get a login shell, but it unfortunately doesn't quite match the bash
environment we get when shell integration isn't enabled (namely, $0
doesn't get the login-shell-identifying "-" prefix).

Instead, this change implements the approach proposed in #7254, which
switches the bash shell integration path to use a .shell command, giving
us the same execution environment as the non-shell-integrated command.
2025-12-11 17:02:14 -05:00
Mitchell Hashimoto
6332fb5c01 macos: some cleanup 2025-12-11 13:59:06 -08:00
Mitchell Hashimoto
f71a25a621 macos: make the tab color indicator SwiftUI 2025-12-11 13:57:39 -08:00
Mitchell Hashimoto
c83bf1de75 macos: simplify terminal controller a bunch 2025-12-11 13:50:24 -08:00
Mitchell Hashimoto
1073e89a0d macos: move context menu stuff in terminal window down to an ext 2025-12-11 13:40:01 -08:00
Mitchell Hashimoto
f559bccc38 macos: clean up setting up the tab menu by using an NSMenu extension 2025-12-11 13:36:49 -08:00
Mitchell Hashimoto
a0089702f1 macos: convert tab color view to SwiftUI 2025-12-11 13:27:51 -08:00
Jeffrey C. Ollie
5dd4e60c31 Fix typo in po/README_TRANS (#9870)
via the its -> via its
2025-12-11 10:06:54 -06:00
Mitchell Hashimoto
04913905a3 macos: tab color is codable for restoration 2025-12-11 07:24:46 -08:00
Mitchell Hashimoto
51589a4e02 macos: move TerminalTabColor to its own file 2025-12-11 07:23:51 -08:00
George Papadakis
1a65c1aae2 feat(macos): add tab color picker to tab context menu 2025-12-11 07:16:26 -08:00
Mitchell Hashimoto
c45a762031 fix(terminal): increase grapheme_bytes instead of hyperlink_bytes during reflow (#9866)
Fixed: When reflowing content with many graphemes, the code incorrectly
increased hyperlink_bytes capacity
instead of grapheme_bytes, causing GraphemeMapOutOfMemory errors.

Added: An unit test for this specific issue. 

This PR was written primarily by Opus.

Closes: #9863
2025-12-11 07:06:51 -08:00
Devzeth
b224b69054 fix(terminal): increase grapheme_bytes instead of hyperlink_bytes during reflow
When reflowing content with many graphemes, the code incorrectly increased hyperlink_bytes capacity
instead of grapheme_bytes, causing GraphemeMapOutOfMemory errors.
2025-12-11 07:03:12 -08:00
Mitchell Hashimoto
86503045e9 fix: prevent integer overflow in hash_map layoutForCapacity (#9871)
Closes #9862
2025-12-11 06:57:23 -08:00
benodiwal
0d8c193bda fix(terminal): prevent integer overflow in hash_map layoutForCapacity
Co-Authored-By: Sachin <sachinbeniwal0101@gmail.com>
2025-12-11 16:43:16 +05:30
Felipe M.B.
3b2f551dc0 Fix typo in po/README_TRANS
via the its -> via its
2025-12-11 07:54:20 -03:00
Jeffrey C. Ollie
dd4493b153 Fix typo in po/README_CONTRIB (#9869)
Change translable to translatable.
2025-12-11 01:54:50 -06:00
Felipe M.B.
f96aca7a3f Fix typo in po/README_CONTRIB
Change translable to translatable.
2025-12-11 04:13:19 -03:00
Mitchell Hashimoto
669733d597 macos: remove iOS signing (dev team) 2025-12-10 21:21:05 -08:00
Mitchell Hashimoto
4a6d551941 macos: don't put NSMenu extension in iOS build 2025-12-10 21:20:39 -08:00
Mitchell Hashimoto
a531ea8b08 Add close tabs on the right action (#9783)
<img width="1694" height="1146" alt="image"
src="https://github.com/user-attachments/assets/f9e1e7e6-7cfe-4760-85fe-def7c10f4110"
/>
2025-12-10 21:09:13 -08:00
Mitchell Hashimoto
3352d5f081 Fix up close right description 2025-12-10 20:57:36 -08:00
Mitchell Hashimoto
eb75d48e6b macos: add xmark to other tab close items 2025-12-10 20:56:07 -08:00
Mitchell Hashimoto
1387dbefad macos: target should be the correct target 2025-12-10 20:50:28 -08:00
Mitchell Hashimoto
dc641c7861 macos: change to NSMenu extension 2025-12-10 20:47:15 -08:00