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

VAIBHAV SHARMA vaibhavks1234 at gmail.com
Sun Jun 15 19:44:18 CEST 2025


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 <85764094+VAIBHAV675 at users.noreply.github.com>
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 <85764094+VAIBHAV675 at users.noreply.github.com>
---
 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnupg-devel/attachments/20250615/8591507c/attachment.html>


More information about the Gnupg-devel mailing list