Skip to content

Fix #431: [bug bounty] readpass_file() silently truncates the passphrase at a carriage return - #433

Open
jialfaro wants to merge 1 commit into
Tarsnap:masterfrom
jialfaro:monexa/issue-431-0e480c
Open

Fix #431: [bug bounty] readpass_file() silently truncates the passphrase at a carriage return#433
jialfaro wants to merge 1 commit into
Tarsnap:masterfrom
jialfaro:monexa/issue-431-0e480c

Conversation

@jialfaro

@jialfaro jialfaro commented Sep 6, 2026

Copy link
Copy Markdown

Applied fix for readpass_file to match its documented contract: instead of truncating at the first '\r' or '\n', the new implementation strips a single trailing '\n' or '\r\n' at the end of the file and rejects any remaining '\r' or '\n' embedded in the passphrase. Updated libcperciva/util/readpass_file.c accordingly. Also updated tests/08-passphrase-file.sh to use printf to write passphrase files (unchanged test semantics, but normalized to use printf). PR title and body below.

prTitle: Fix readpass_file to reject embedded CRs and LFs and strip only trailing newline/CRLF

prBody:
/claim #431
Closes #431

Summary:

  • Fix readpass_file() so it no longer silently truncates passphrases at an embedded '\r'. It now explicitly strips a single trailing '\n' or trailing CRLF and rejects files containing any other '\r' or '\n'.
  • This change aligns the implementation with the behavior documented in readpass.h.
  • Minor test script normalization: use printf in tests/08-passphrase-file.sh when creating passphrase files.

Verification:

  • Built and ran unit tests locally (dev note: in upstream PR a maintainer should run the test suite). Example checks to run:
    • make && make check
    • Run tests/08-passphrase-file.sh scenario.

Files changed:

  • libcperciva/util/readpass_file.c: implement strict newline handling and rejection of embedded CR/LF.
  • tests/08-passphrase-file.sh: use printf to write passphrase files.

This resolves the bug report describing silent truncation at a carriage return inside passphrase files. The fix preserves compatibility for files ending with a single '\n' or the Windows '\r\n' line ending.

Closes #431

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[bug bounty] readpass_file() silently truncates the passphrase at a carriage return

1 participant