Skip to content

history: close COMMIT_EDITMSG before launching the editor#2158

Open
dscho wants to merge 1 commit into
gitgitgadget:masterfrom
dscho:fix-fd-leak-in-history-reword
Open

history: close COMMIT_EDITMSG before launching the editor#2158
dscho wants to merge 1 commit into
gitgitgadget:masterfrom
dscho:fix-fd-leak-in-history-reword

Conversation

@dscho

@dscho dscho commented Jun 25, 2026

Copy link
Copy Markdown
Member

I noticed this problem while trying to whip MinGit-BusyBox into a better shape during the -rc phase. Technically, this is not a fix for a regression during the v2.55.0 period, but I figured it'd be better to send it now anyway than to forget about sending it after v2.55.0 is released.

Cc: Patrick Steinhardt ps@pks.im

The `git history reword` and `git history fixup` subcommands prepare the
commit message by writing it to COMMIT_EDITMSG and then opening that same
file a second time, in append mode, through `wt_status`'s `fp` field to
append the status information. That second handle is never closed before
`launch_editor()` runs, so the editor is started while git still holds
the file open.

Everywhere this leaks a file descriptor, but on Windows it is outright
broken: a process cannot replace a file that another process keeps open,
so an editor that rewrites COMMIT_EDITMSG by creating a fresh file in its
place fails. This surfaced while running Git for Windows' test suite with
BusyBox' `ash` as the POSIX shell: the fake editor's `cp message "$1"`
aborts with "cp: can't create '.../COMMIT_EDITMSG': File exists" (MSYS2's
coreutils `cp` hides the problem via its POSIX unlink emulation, BusyBox'
native `cp` does not), making t3451-history-reword and t3453-history-fixup
fail wholesale.

Close the handle once the status has been written, before handing the
file off to the editor.

Assisted-by: Opus 4.8
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
@dscho dscho self-assigned this Jun 25, 2026
@dscho

dscho commented Jun 25, 2026

Copy link
Copy Markdown
Member Author

/submit

@gitgitgadget

gitgitgadget Bot commented Jun 25, 2026

Copy link
Copy Markdown

Error: Invalid login: 454-4.7.0 Too many login attempts, please try again later. For more information,
454-4.7.0 go to
454 4.7.0 https://support.google.com/mail/answer/7126229 38308e7fff4ca-3999af9f3a9sm40986481fa.7 - gsmtp

@gitgitgadget

gitgitgadget Bot commented Jun 25, 2026

Copy link
Copy Markdown

Submitted as pull.2158.git.1782412427801.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-2158/dscho/fix-fd-leak-in-history-reword-v1

To fetch this version to local tag pr-2158/dscho/fix-fd-leak-in-history-reword-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-2158/dscho/fix-fd-leak-in-history-reword-v1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant