Skip to content

Unix: do not overwrite keyfiles and header backups in text mode - #1965

Open
flatstik wants to merge 2 commits into
veracrypt:masterfrom
flatstik:fix-1962-text-overwrite
Open

flatstik wants to merge 2 commits into
veracrypt:masterfrom
flatstik:fix-1962-text-overwrite

Conversation

@flatstik

@flatstik flatstik commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1962.

  • --create-keyfile refuses an existing file unless --force is given, without asking, so that scripts are not stopped by a new prompt (as suggested in the issue). The check comes before the random pool is enriched.
  • --backup-headers is interactive and already asks for the file name, so it asks before replacing an existing file, with the prompt of the file dialog of the graphical interface, as text mode already does for new containers (4edad72). --force overwrites without asking.

Tested:

The new test adds lines next to test_mount_helper.py in .github/workflows/build-linux.yml, as do the other PRs split from #1963, so whichever is merged later conflicts there; I will rebase it.

Split from #1963, with #1968 (#1958), #1967 (#1959), #1966 (#1960), #1964 (#1961).

--create-keyfile and --backup-headers opened the destination with
O_CREAT|O_TRUNC without checking whether it existed. Recreating an
existing keyfile replaced it with new random data, so every volume that
used it could no longer be mounted, and an existing file chosen for a
header backup was truncated.

--create-keyfile now refuses an existing file unless --force is given,
without asking, so that scripts are not stopped by a new prompt. The
check comes before the random pool is enriched.

--backup-headers is interactive and already asks for the file name, so
it asks before replacing an existing file, with the prompt of the file
dialog of the graphical interface, as text mode already does for new
containers (4edad72). --force overwrites without asking.

Fixes veracrypt#1962
Tests/test_text_overwrite.py checks overwriting keyfiles and header
backups in text mode against the installed package in the Linux
workflow.
@flatstik
flatstik force-pushed the fix-1962-text-overwrite branch from 697016e to 65f7b2f Compare October 27, 2026 14:02
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.

Options --create-keyfile and --backup-headers overwrite existing files without asking

1 participant