Skip to content

Fix: CLI: cleanup clipboard on CTRL+C #13549 - #13552

Open
DRIP-70 wants to merge 2 commits into
keepassxreboot:developfrom
DRIP-70:develop
Open

Fix: CLI: cleanup clipboard on CTRL+C #13549#13552
DRIP-70 wants to merge 2 commits into
keepassxreboot:developfrom
DRIP-70:develop

Conversation

@DRIP-70

@DRIP-70 DRIP-70 commented Jul 28, 2026

Copy link
Copy Markdown

Fixes #13549

At the moment, when keepassxc-cli clip is interrupted using Ctrl+C (SIGINT) or SIGTERM before the countdown timeout expires, the OS ends the process immediately, leaving the password available on the clipboard.

This PR adds signal handling to Clip::executeWithDatabase():

  • Intercepts SIGINT and SIGTERM using an std::atomic signal flag.
  • Replaces the single 1-second blocking sleep loop with a fine-grained loop (100ms sleep intervals) that continuously polls the atomic flag.
  • Calls Utils::clipText("") to ensure that the clipboard is cleared before restoring signal handlers and exiting gracefully upon catching a signal or reaching timeout expiration.

Generative AI was used to refine the code.

Screenshots

Posting video since clipboard is used and it is difficult to screenshot

Video.Fix.mp4

Testing strategy

Manually tested on Fedora Linux:

  1. Executed "./keepassxc-cli clip 10".
  2. Made sure that the entry's password was correctly copied to the clipboard.
  3. Pressed Ctrl+C after a few seconds while the countdown was active.
    • Verified that the loop exited immediately, printed "Clipboard cleared!", and left the clipboard empty(by pressing Ctrl+V).
  4. Executed "./keepassxc-cli clip 3" and allowed the timeout to expire normally(to check if existing function isnt broken).
    • Verified that the countdown is finishing normally and clears the clipboard as it should.

Type of change

  • ✅ Bug fix (non-breaking change that fixes an issue)

@DRIP-70

DRIP-70 commented Jul 28, 2026

Copy link
Copy Markdown
Author

It seems I don't know how to use comments, please use the Files changed tab for understanding those.

@droidmonkey

Copy link
Copy Markdown
Member

Did you test this? I am not clear how this code is any different then before.

This would be the desired implementation
https://doc.qt.io/qt-6/unix-signals.html

Comment thread src/cli/Clip.cpp Outdated
@keepassxreboot keepassxreboot deleted a comment from DRIP-70 Jul 28, 2026
@keepassxreboot keepassxreboot deleted a comment from DRIP-70 Jul 28, 2026
@keepassxreboot keepassxreboot deleted a comment from DRIP-70 Jul 28, 2026
@keepassxreboot keepassxreboot deleted a comment from DRIP-70 Jul 28, 2026
@keepassxreboot keepassxreboot deleted a comment from DRIP-70 Jul 28, 2026
@keepassxreboot keepassxreboot deleted a comment from DRIP-70 Jul 28, 2026
DRIP-70

This comment was marked as resolved.

@DRIP-70

DRIP-70 commented Jul 28, 2026

Copy link
Copy Markdown
Author

Did you test this? I am not clear how this code is any different then before.

This would be the desired implementation https://doc.qt.io/qt-6/unix-signals.html

Yes, I have tested this, the video attached actually shows that.

@DRIP-70
DRIP-70 requested a review from droidmonkey July 28, 2026 13:31
@varjolintu varjolintu added the pr: ai-assisted Pull request contains significant contributions by generative AI label Jul 28, 2026
@droidmonkey

Copy link
Copy Markdown
Member

The code doesnt change any code paths, your use of the global variable appears to be totally unnecessary. I think the fact that you are overriding the handler of the terminal signals is enough. You are basically ignoring them.

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

Labels

pr: ai-assisted Pull request contains significant contributions by generative AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLI: cleanup clipboard on CTRL+C

3 participants