cmd/commands: read full stdin for lncli unlock --stdin #10784
🟡 PR Severity: MEDIUM
Automated classification | 2 files (excl. tests/generated) | 16 lines changed
<details>
<summary>🟡 <strong>Medium</strong> (1 file)</summary>
cmd/commands/cmd_walletunlocker.go - CLI client command under cmd/; classified as MEDIUM regardless of the walletunlocker name in the path</details>
<details>
<summary>🟢 <strong>Low</strong> (1 file)</summary>
docs/release-notes/release-notes-0.22.0.md - Release notes documentation</details>
Analysis
This PR modifies a CLI command file under cmd/commands/ and adds a corresponding test. Per the classification rules, files under cmd/ are always MEDIUM (CLI client code), even when the filename references a server-side package like walletunlocker. The actual server-side walletunlocker/* package is not touched. The release notes file is LOW, but the highest severity file determines the PR severity, so this is MEDIUM.
No severity bump was triggered: only 2 non-test files changed (threshold: >20) and only 16 non-test lines changed (threshold: >500).
---
<sub>To override, add a severity-override-{critical,high,medium,low} label.</sub>
<\!-- pr-severity-bot -->
Summary of Changes
Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses an issue where wallet passwords containing newline characters were being truncated when provided via the --stdin flag. By switching from line-based reading to reading until EOF, the command now correctly supports complex passwords while maintaining compatibility with common shell usage patterns.
Highlights
Improved Stdin Password Handling: Updated the lncli unlock --stdin command to read the entire input until EOF instead of stopping at the first newline character, ensuring passwords with embedded newlines are handled correctly.
Maintained Backward Compatibility: Implemented logic to strip only the final trailing newline or carriage return, preserving the functionality for standard shell piping.
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
<b>Invoking Gemini</b>
You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
Feature | Command | Description
--- | --- | ---
Code Review | /gemini review | Performs a code review for the current pull request in its current state.
Pull Request Summary | /gemini summary | Provides a summary of the current pull request in its current state.
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help | /gemini help | Displays a list of available commands.
<b>Customization</b>
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.
</details>
[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.
Code Review
This pull request modifies the lncli unlock --stdin command to read the password until EOF, allowing for passwords with embedded newlines. It also updates the trimming logic to only remove a single trailing newline or carriage return. New test cases were added to verify these changes across different input formats, and the release notes were updated. I have no feedback to provide.
The switch to io.ReadAll is a great fix for the truncation issue. However, we should handle the err returned here before proceeding to the trim logic, just in case the stdin stream fails or is interrupted.
pw, err = io.ReadAll(stdin)
if err != nil {
return err
}
Overall, this is a solid fix and the test coverage is excellent. I've left one small suggestion regarding error handling for the io.ReadAll call. Once that's addressed, I think this is ready to go!
Good catch, applied in the latest push. io.ReadAll error is now returned before trimming so a partial read can no longer slip into the unlock call.
Rebased on master and addressed @TechLateef's review feedback — io.ReadAll error is now handled before the trim step. Ready for another look.
LGTM! The error handling looks great now. It looks like some recent changes in the main branch have introduced a merge conflict, so you'll just need to rebase/resolve that before this can be merged.
@techlateef: review reminder
@0xfandom, remember to re-request review from reviewers when ready
!lightninglabs-deploy mute
Rebased on latest master. The only conflict was in the 0.22.0 release notes bug-fix section (new entries landed above mine); kept both and re-appended my line. Code and tests are unchanged from the approved version — go test ./cmd/commands/ still passes locally.
Rebased onto latest master again — clean this time, no release notes conflict. Code and tests are unchanged from the version @TechLateef approved; go test ./cmd/commands/ still passes.
This one has been sitting for a while — anything else needed from my side before it can go in?
Hi @0xfandom, thanks for taking the time to put this together.
Per the new contributor section of the contribution guidelines, we don't prioritize review of PRs from authors without a track record in the project. Given the current review load, I'm closing this rather than letting it sit.
Since #5584 already covers this, we'll handle it from that issue; if a fix is warranted a maintainer will pick it up.
If you'd like to contribute going forward, reviewing open PRs and helping triage issues is the path we recommend. It's a stronger signal of understanding than a first patch, and it makes it a lot easier for us to prioritize your PRs later.
TechLateef
0xfandom
Change Description
lncli unlock --stdinreads the password usingbufio.ReadBytes('\n'), which terminates at the first newline byte. A wallet password that legitimately contains a newline (for example one generated from random bytes) gets silently truncated, and the unlock fails even though the same password works fine over REST/gRPC.This switches the
--stdinbranch incmd/commands/cmd_walletunlocker.gotoio.ReadAll(stdin)so the password is consumed up to EOF, and trims a single trailing\n(with optional\r) so the commonecho "pw" | lncli unlock --stdininvocation still works as before. Three new table-driven test cases cover an embedded newline, a stdin payload with no trailing newline, and a CRLF terminator.Fixes #5584.
Steps to Test
1.
go test ./cmd/commands/... -run TestUnlock -v— allsuccess_stdin_*subtests pass.2. Manual end-to-end:
Pull Request Checklist
Testing
Code Style and Documentation