Skip to content

Fix process waiting and mode-enable robustness in sops.el#20

Open
ArthurHeymans wants to merge 2 commits into
djgoku:mainfrom
ArthurHeymans:fix-manual-sops-save-plaintext
Open

Fix process waiting and mode-enable robustness in sops.el#20
ArthurHeymans wants to merge 2 commits into
djgoku:mainfrom
ArthurHeymans:fix-manual-sops-save-plaintext

Conversation

@ArthurHeymans

Copy link
Copy Markdown

Two independent bugs are addressed in this PR: a potential infinite loop in sops--run when a subprocess sentinel is delayed or never fires, and incomplete state management when manually enabling sops-mode on an already-open buffer.

Process waiting fix (sops--run)

  • The synchronous wait loop now checks (process-live-p proc) in addition to the sentinel-set done flag, preventing an infinite spin if the sentinel is delayed or suppressed
  • Adds a final (accept-process-output proc 0 nil t) call after the loop to drain any remaining output that arrived between the last poll and process exit
  • Covers the regression with a new test (sops-test--run-does-not-require-sentinel-flag) that replaces the sentinel with a no-op and asserts the call completes within 2 seconds

Manual sops-mode enable fixes

  • Before decrypting, the mode now checks for a modified buffer and signals a user-error rather than silently overwriting unsaved edits with plaintext
  • On successful decryption, sops-mode and sops--state are explicitly set to their correct values; previously the mode could be enabled with stale or missing state
  • sops--revert-buffer now explicitly reinstalls sops-mode, sops--state, and sops--restore-after-major-mode-change after a successful decrypt, guarding against major-mode setup that clears local variables during sops--decrypt-buffer
  • New tests cover: successful manual enable, rejection of a modified buffer, and protection reinstallation after a mode-reset during revert

sops--run waited only for a sentinel-maintained flag before reading the
process result. In interactive sessions the subprocess can exit before
the sentinel has run, which leaves save-buffer spinning forever even
though the sops command is already done.

Wait while the process is live as well as while the sentinel flag is
unset, then perform a final non-blocking output drain before reading
stdout and stderr. Add a regression test that replaces the sentinel with
a no-op to prove sops--run does not depend solely on that flag.
Manual sops-mode activation can happen after a file did not match the
find-file prefilter, leaving the buffer full of ciphertext. Previously
the mode installed encrypt-on-save hooks without decrypting first; a
later revert or mode reset could drop those hooks and a normal save
would write plaintext.

On manual enable, verify the visited file is a SOPS file, refuse to
overwrite modified buffer contents, decrypt the file, and then install
the normal protections. On revert, reassert sops-mode state and restore
local hooks after a successful decrypt so plaintext major-mode setup
cannot leave the buffer unprotected.

Add regression tests for manual activation, modified-buffer refusal, and
revert hook restoration.
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