Review report

bitcoin/bitcoin: PR #36767

2 minor findings · 2 suggestions

Findings

Link

[minor] · Failed-creation cleanup can unlink a concurrently opened wallet

On POSIX, narrowly scheduled same-name createwallet or loadwallet calls can open the database after a failed creation closes it, then lose its pathname to the failed attempt's cleanup.

Location: src/wallet/wallet.cpp:399 (head).

Details and suggested fix

The existence snapshot does not reserve the wallet path through cleanup. A second createwallet can pass format detection and require_create for the unused name, then remain suspended before acquiring SQLite's exclusive lock while the external-signer creation runs and fails. Unwinding CreateNew closes the failed attempt's database before fs::remove runs. The second creator can then acquire the lock and complete creation, including generating private-key descriptors, before cleanup resumes. A loadwallet can likewise open the partial database in the close-to-remove interval; g_loading_wallet_set protects loads only. POSIX permits the subsequent unlink even with the other connection open, leaving its database on an orphaned inode that disappears after close. Removing its journal or directory can also make later writes fail. This requires conflicting operations from trusted clients and a very narrow schedule; no production occurrence was identified. Reserve the resolved wallet path across both creation and loading, covering the existence snapshot, database lifetime, and cleanup.


Link

[minor] · Failed-creation cleanup deletes a pre-existing dangling wallet.dat symlink

A dangling wallet.dat symlink counts as absent in the snapshot, so failed creation can delete the user's link while leaving the partial database at its target.

Location: src/wallet/wallet.cpp:371 (head).

Details and suggested fix

In an existing wallet directory, fs::exists follows wallet.dat and returns false for a dangling symlink. The format probes also see no database, allowing SQLite's CREATE open to follow the link and create its target on POSIX. If external-signer setup then fails, created_wallet_file is true, but database->Files() contains the original link pathname. Cleanup therefore removes the pre-existing link rather than the target it created. A later successful creation writes a regular wallet.dat in the wallet directory instead of using the user's chosen location. No current workflow that pre-creates such a dangling link before createwallet was identified, so production impact is unconfirmed. Use symlink_status to distinguish an existing directory entry from an absent one before deciding that cleanup owns it.


Optional improvements

Link

[suggestion] · Pre-existing-file test leaves the blocked wallet name unasserted

The pre-existing-file case checks filenames but leaves unasserted that the empty wallet.dat becomes a recognized partial database and prevents reuse of the name.

Location: test/functional/wallet_signer.py:269 (head).

Details and suggested fix

The preceding assertion establishes an empty directory, so touch creates a zero-length wallet.dat. Format detection does not recognize it, and SQLite initializes a wallet database before CreateNew writes metadata and flags and reaches the failing signer setup. Because the file existed at the snapshot, cleanup keeps this rewritten database. It would now appear in listwalletdir, and another createwallet would fail with 'Database already exists'. The filename comparison correctly checks entry retention but does not document this outcome. Extend this case to assert that the name is listed and that retrying returns the existing-database message, documenting the limitation explicitly. The same empty-file behavior exists at base.


Link

[suggestion] · External-signer creation changes lack a release note

The GUI crash fix and changed createwallet error code and message are user-visible but have no release note.

Location: src/wallet/wallet.cpp:387 (head).

Details and suggested fix

External-signer setup exceptions now return RPC_WALLET_ERROR (-4) with a 'Wallet creation failed. ' prefix instead of the generic -1 response with bare exception text. Clients matching those errors will see different results. The same handling replaces the GUI abort with its existing error dialog, and the new cleanup removes newly created database files after setup failure. Consider a short PR-specific release note covering these changes, as requested for API and user-visible changes in doc/developer-notes.md. Maintainers may consider the error-code change for previously uncaught exceptions too minor to require one.


Coverage details