From a07b1b75032e07d09e824a9e5e382c949901c99b Mon Sep 17 00:00:00 2001 From: Pau Espin Pedrol Date: Thu, 15 Feb 2018 17:23:50 +0100 Subject: [PATCH] login: Follow timeout guidelines when password returns in time If there's noise in the serial line, it will usually end up in Password: prompt and after timeout, autoboot process will be triggered. However, if the noise is translated to \n or whatever character code used to finish the password string, the login() funcion will against request the password() with the full timeout. If the noise keeps printing the \n or similar character with a high frequency, barebox will become stuck in the boot process. Related: SYS#4128 --- commands/login.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/commands/login.c b/commands/login.c index bf5085c85..ee3c31ee1 100644 --- a/commands/login.c +++ b/commands/login.c @@ -25,6 +25,7 @@ #include #include #include +#include #define PASSWD_MAX_LENGTH (128 + 1) @@ -44,6 +45,7 @@ static int do_login(int argc, char *argv[]) int passwd_len, opt; int timeout = login_timeout; char *timeout_cmd = "boot"; + uint64_t start; console_allow_input(true); if (!is_passwd_enable()) { @@ -62,19 +64,21 @@ static int do_login(int argc, char *argv[]) if (optind != argc) timeout_cmd = argv[optind]; + start = get_time_ns(); do { puts("Password: "); passwd_len = password(passwd, PASSWD_MAX_LENGTH, LOGIN_MODE, timeout); - if (passwd_len < 0) { - console_allow_input(false); - run_command(timeout_cmd); - } + if (passwd_len < 0) + goto trigger_timeout; if (check_passwd(passwd, passwd_len) == 1) return 0; - } while(1); + } while(!is_timeout(start, timeout * SECOND) || timeout == 0); +trigger_timeout: + console_allow_input(false); + run_command(timeout_cmd); return 0; }