907a3b94cd
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
48 lines
1.3 KiB
Diff
48 lines
1.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Peter Jones <pjones@redhat.com>
|
|
Date: Mon, 29 Aug 2022 15:22:10 -0400
|
|
Subject: [PATCH] read_password(): only prune CR/NL from the end of the file
|
|
|
|
Right now, when we read the password/PIN from a file, we're pruning the
|
|
end of the string from the file we read indiscriminately. If you don't
|
|
have a newline, that means we're cutting off the final digits of the
|
|
text.
|
|
|
|
This changes it to prune only common special characters from the
|
|
pinfile, but also to prune /all/ of them.
|
|
|
|
Related: rhbz#2122777
|
|
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
---
|
|
src/password.c | 10 +++++++++-
|
|
1 file changed, 9 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/src/password.c b/src/password.c
|
|
index 8eb1c33..ac1866e 100644
|
|
--- a/src/password.c
|
|
+++ b/src/password.c
|
|
@@ -79,6 +79,7 @@ read_password(FILE *in, FILE *out, char *buf, size_t bufsz)
|
|
int infd = fileno(in);
|
|
struct termios tio;
|
|
char *ret;
|
|
+ int len;
|
|
|
|
ingress();
|
|
ret = fgets(buf, bufsz, in);
|
|
@@ -96,7 +97,14 @@ read_password(FILE *in, FILE *out, char *buf, size_t bufsz)
|
|
if (ret == NULL)
|
|
return -1;
|
|
|
|
- buf[strlen(buf)-1] = '\0';
|
|
+ len = strlen(buf);
|
|
+ while (len > 0 && (buf[len-1] == '\r' || buf[len-1] == '\n')) {
|
|
+ buf[len-1] = '\0';
|
|
+ len--;
|
|
+ }
|
|
+ if (len == 0)
|
|
+ return -1;
|
|
+
|
|
egress();
|
|
return 0;
|
|
}
|