diff mbox series

[ima-evm-utils,1/2] Strip trailing newline from password entered via prompt

Message ID 20230613131542.3603874-2-stefanb@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series Fix issues related to password | expand

Commit Message

Stefan Berger June 13, 2023, 1:15 p.m. UTC
The password entered via the prompt contains the trainling newline ('\n')
and therefore likely none of the passwords used for keys are 'working',
meaning using a password-protected key is likely to fail when using the
prompt. Therefore, remove the trailing newline from the password.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
 src/evmctl.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/src/evmctl.c b/src/evmctl.c
index c35a28c..4b68091 100644
--- a/src/evmctl.c
+++ b/src/evmctl.c
@@ -2936,6 +2936,7 @@  static char *get_password(void)
 	struct termios flags, tmp_flags;
 	char *password, *pwd;
 	int passlen = 64;
+	size_t actlen;
 
 	password = malloc(passlen);
 	if (!password) {
@@ -2969,6 +2970,11 @@  static char *get_password(void)
 		return NULL;
 	}
 
+	/* strip trailing '\n' */
+	actlen = strlen(password);
+	if (actlen > 0 && password[actlen - 1] == '\n')
+		password[actlen - 1] = 0;
+
 	return password;
 }