Repository navigation
Conversation
When curl cannot open the terminal it reads the password from stdin, and getpass_r() always replaced the last byte read with the null terminator, assuming it was the newline from pressing enter. A password piped without a trailing newline, as in 'printf pass | curl -u alice', lost its last character. Only remove a trailing newline, and read at most buflen - 1 bytes to leave room for the terminator.
|
You should be able to craft a test using a password file created with nonewline=yes and passed in to curl's stdin.
|
|
Thanks, that works. I added test 1696 ( One catch: if the test suite runs with a controlling terminal, curl opens |
| # only when curl cannot open the terminal | ||
| <precheck> | ||
| %PERL -e 'if(open(T, "/dev/tty")) {print "Test requires no controlling terminal"} elsif($^O =~ /MSWin32|msys/) {print "Test requires a POSIX getpass_r"} elsif(open(C, "../lib/curl_config.h")) {print "Test requires the getpass_r in src" if grep(/define HAVE_GETPASS_R 1/, readline(C))}' | ||
| </precheck> |
There was a problem hiding this comment.
This looks like a maintenance headache and fragile in many ways.
I suggest replacing with something solid and universal. If not possible,
being an obscure issue, I think no dedicatedl test is also fine.
|
Agreed, I dropped test 1696; the PR is now just the fix in |
1818ff9 to
5a9070a
Compare
There was a problem hiding this comment.
🟢 Approval recommended
The focused change corrects password truncation while safely terminating the buffer for the existing caller.
No open issues 🎉
What changed in this PR
Fixes password input handling so stdin input without a trailing newline retains its final character.
Changes:
- Removes only a trailing newline.
- Reserves space for the terminator and safely handles empty input and read errors.
| File | Description |
|---|---|
| src/tool_getpass.c | Preserves password bytes and ensures null termination. |
Review effort: Balanced
|
Thanks! |
Without a terminal, curl reads the password from stdin, and
getpass_r()always replaces the last byte read with the terminator, assuming it is the newline. So a password piped without a newline loses its last character:sends
alice:pas(printf 'pass\n'sendsalice:pass).This only removes a trailing newline, and reads at most
buflen - 1bytes so there is always room for the terminator (a full buffer also lost its last byte before).There is no dedicated test: a stdin-only test is fragile, because curl reads the password from
/dev/ttywhenever it can open one.This issue was found by an LLM-Enhanced Static Analysis Engine and verified manually.