Repository navigation
fix(hostkey): close known_hosts file when appending a key fails - #500
Merged
Merged
Conversation
The accept-new callback returned without closing the known_hosts file when WriteString failed, leaking the descriptor. Close it before returning the write error. Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
There was a problem hiding this comment.
🟢 Approval recommended
The targeted leak is fixed, the success path is unchanged, and no unresolved review issues remain.
No open issues 🎉
What changed in this PR
This pull request fixes a file-descriptor leak in the SSH accept-new host-key callback by closing known_hosts before returning a write error.
Changes:
- Closes the
known_hostsfile when appending a key fails. - Preserves the existing successful write-and-close path.
| File | Description |
|---|---|
protocol/ssh/hostkey/callbacks.go |
Closes the file on WriteString failure to prevent descriptor leaks. |
Review effort: Lite
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the accept-new host key callback failed to append a key to known_hosts, it returned the
WriteStringerror without closing the file, leaking the descriptor.The file is now closed before the write error is returned. The success path is unchanged.
No test: a failing write on a regular file can only be forced portably with something like
/dev/full(Linux only), and even then the test could only check that an error comes back, not that the descriptor was closed. That's a lot of setup to check a one-lineClose.