From f23d25f5e5165a4615225c3604f0a8b59d2d2fe9 Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Thu, 7 Jun 2012 23:49:00 +0100 Subject: [PATCH] Fix GnuTLS PKCS#11 PIN request function Signed-off-by: David Woodhouse --- main.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/main.c b/main.c index 4b02155..f4d21a6 100644 --- a/main.c +++ b/main.c @@ -397,7 +397,6 @@ static int gtls_pin_func(void *user, int attempt, const char *token_url, { char *password, *p; struct termios t; - int len; printf ("PIN required for token '%s' with URL '%s'\n", token_label, token_url); @@ -422,17 +421,18 @@ static int gtls_pin_func(void *user, int attempt, const char *token_url, t.c_lflag |= ECHO; tcsetattr(0, TCSANOW, &t); printf("\n"); - - if (!p || !strlen(password)) { + + if (!p || !strlen(password) || password[0] == '\n') { free(password); return -GNUTLS_E_INSUFFICIENT_CREDENTIALS; } - len = strlen(password); - if (len > pin_max) - len = pin_max; + p = strchr(password, '\n'); + if (p) + *p = 0; - memcpy(pin, password, len); + strncpy(pin, password, pin_max); + pin[pin_max-1] = 0; free(password); return 0; -- 2.7.4