Subject: [PATCH] g10 : passphrase.c : read_passphrase_from_fd : Strip trailing carriage return from passphrase read from file generated on windows

VAIBHAV SHARMA via Gnupg-devel <[email protected]>
Newsgroups gmane.comp.encryption.gpg.devel
Message-ID <CAJ4=z3RHGXLGpVghVHHpip+pC5SdV5gtNks1AgjSqMQTNDKuhw@mail.gmail.com>
Hello,

On Windows, passphrase files may have CRLF (\r\n) line endings.
This patch removes the trailing '\r' if present, avoiding potential
passphrase mismatches during decryption or signing operations.
I have requested this patch after personally facing the issue with a
passphrase file generated on windows as it was silently including \r in the
password and the decryption attempt was failing.
Please find the below attached patch details.

Thanks,
Vaibhav Sharma

---
>From e0e6acca96405c2a291a11074f510e66774925d6 Mon Sep 17 00:00:00 2001
From: VAIBHAV SHARMA <[email protected]>
Date: Sun, 15 Jun 2025 17:29:29 +0000
Subject: [PATCH] g10: Handle CRLF endings in passphrase file input *
 g10/passphrase.c (read_passphrase_from_fd): Trim trailing \r character in
 passphrase input to correctly handle CRLF endings.

Signed-off-by: VAIBHAV SHARMA <[email protected]>
---
 g10/passphrase.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/g10/passphrase.c b/g10/passphrase.c
index c5ec8eae4..32bbc74f6 100644
--- a/g10/passphrase.c
+++ b/g10/passphrase.c
@@ -150,6 +150,12 @@ read_passphrase_from_fd( int fd )
         break;
     }
   pw[i] = 0;
+
+  /* Fix for Windows CRLF line endings for passphrase file generated on
windows:
+     If the passphrase ends with a carriage return character ('\r') due to
CRLF line endings, strip it. */
+  if (i > 0 && pw[i-1] == '\r')
+    pw[i-1] = 0;
+
   if (!opt.batch && opt.pinentry_mode != PINENTRY_MODE_LOOPBACK)
     tty_printf("\b\b\b   \n" );

-- 
2.49.0

_______________________________________________
Gnupg-devel mailing list
[email protected]
https://lists.gnupg.org/mailman/listinfo/gnupg-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.