Skip to content

cmd/commands: read full stdin for lncli unlock --stdin#10784

Open
0xfandom wants to merge 2 commits intolightningnetwork:masterfrom
0xfandom:fix/5584-lncli-unlock-stdin-eof
Open

cmd/commands: read full stdin for lncli unlock --stdin#10784
0xfandom wants to merge 2 commits intolightningnetwork:masterfrom
0xfandom:fix/5584-lncli-unlock-stdin-eof

Conversation

@0xfandom
Copy link
Copy Markdown

@0xfandom 0xfandom commented May 1, 2026

Change Description

lncli unlock --stdin reads the password using bufio.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 --stdin branch in cmd/commands/cmd_walletunlocker.go to io.ReadAll(stdin) so the password is consumed up to EOF, and trims a single trailing \n (with optional \r) so the common echo "pw" | lncli unlock --stdin invocation 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 — all success_stdin_* subtests pass.
  2. Manual end-to-end:
    printf 'first\nsecond' > /tmp/pw
    lncli create   # set wallet password to "first\nsecond" via this file
    lncli unlock --stdin < /tmp/pw   # previously rejected, now succeeds
    

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

  • The change is not insubstantial (typo fixes not accepted).
  • Adheres to Code Documentation and Commenting guidelines, 80-char line wraps.
  • Commits follow Ideal Git Commit Structure.
  • Any new logging statements use appropriate subsystem and level.
  • Any new lncli commands have tags in proto comments.
  • Release notes added (or [skip ci] in commit message for small changes).

0xfandom added 2 commits May 1, 2026 18:48
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
@0xfandom 0xfandom force-pushed the fix/5584-lncli-unlock-stdin-eof branch from b0fe11d to e50aec4 Compare May 1, 2026 13:19
@github-actions github-actions Bot added the severity-medium Focused review required label May 1, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

🟡 PR Severity: MEDIUM

Automated classification | 2 files (excl. tests/generated) | 16 lines changed

🟡 Medium (1 file)
  • cmd/commands/cmd_walletunlocker.go - CLI client command under cmd/*; classified as MEDIUM regardless of the walletunlocker name in the path
🟢 Low (1 file)
  • docs/release-notes/release-notes-0.22.0.md - Release notes documentation

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).


To override, add a severity-override-{critical,high,medium,low} label.
<!-- pr-severity-bot -->

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 --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.
  • Expanded Test Coverage: Added three new table-driven test cases to verify handling of embedded newlines, missing trailing newlines, and CRLF terminators.

🧠 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 Assist

The 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 /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.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  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.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@lightninglabs-deploy
Copy link
Copy Markdown
Collaborator

@0xfandom, remember to re-request review from reviewers when ready

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

Labels

severity-medium Focused review required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lncli unlock --stdin uses newline instead of EOF as a terminator

2 participants