cmd/commands: read full stdin for lncli unlock --stdin#10784
cmd/commands: read full stdin for lncli unlock --stdin#107840xfandom wants to merge 2 commits intolightningnetwork:masterfrom
Conversation
The --stdin branch of `lncli unlock` used bufio.ReadBytes('\n'), which
stops at the first newline byte and silently truncates passwords that
contain embedded newlines. A wallet password generated from random
bytes can legitimately contain a newline, in which case the unlock
attempt fails even though the same password works over REST/gRPC.
Switch to io.ReadAll so the password is consumed up to EOF, and only
trim a single trailing newline (with optional CR) so the common
`echo "pw" | lncli unlock --stdin` invocation keeps working without
leaking the trailing byte added by the shell. New table-driven test
cases cover an embedded newline, no trailing newline, and a CRLF
terminator.
Fixes lightningnetwork#5584
b0fe11d to
e50aec4
Compare
🟡 PR Severity: MEDIUM
🟡 Medium (1 file)
🟢 Low (1 file)
AnalysisThis PR modifies a CLI command file under No severity bump was triggered: only 2 non-test files changed (threshold: >20) and only 16 non-test lines changed (threshold: >500). To override, add a |
Summary of ChangesHello, I'm Gemini Code Assist1! 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 Highlights
🧠 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. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization 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 Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 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. Footnotes
|
There was a problem hiding this comment.
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.
|
@0xfandom, remember to re-request review from reviewers when ready |
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
go test ./cmd/commands/... -run TestUnlock -v— allsuccess_stdin_*subtests pass.Pull Request Checklist
Testing
Code Style and Documentation