From ccbfe01427442b427ec0b460dfd994fe0bc8bd49 Mon Sep 17 00:00:00 2001 From: jok325 Date: Tue, 28 Apr 2020 22:31:22 +0200 Subject: [PATCH] Used maximum password request tries. Issue #913 --- src/rnp/fficli.cpp | 11 ++++++++--- src/rnp/rnpcfg.cpp | 6 +++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/rnp/fficli.cpp b/src/rnp/fficli.cpp index ec8a157265..a45e050d6a 100644 --- a/src/rnp/fficli.cpp +++ b/src/rnp/fficli.cpp @@ -252,6 +252,7 @@ ffi_pass_callback_stdin(rnp_ffi_t ffi, char buffer[MAX_PASSWORD_LENGTH]; bool ok = false; cli_rnp_t *rnp = static_cast(app_ctx); + int pswdtries = 1; if (!ffi || !pgp_context) { goto done; @@ -286,9 +287,13 @@ ffi_pass_callback_stdin(rnp_ffi_t ffi, goto done; } if (strcmp(buf, buffer) != 0) { - fputs("\nPasswords do not match!", rnp->userio_out); - // currently will loop forever - goto start; + fputs("\nPasswords do not match!\n", rnp->userio_out); + fflush(rnp->userio_out); + if (rnp->pswdtries > 0 && ++pswdtries > rnp->pswdtries) { + goto done; + } else { + goto start; + } } } ok = true; diff --git a/src/rnp/rnpcfg.cpp b/src/rnp/rnpcfg.cpp index 2055d07faa..7c06b59967 100644 --- a/src/rnp/rnpcfg.cpp +++ b/src/rnp/rnpcfg.cpp @@ -486,10 +486,10 @@ rnp_cfg_get_pswdtries(const rnp_cfg_t *cfg) numtries = rnp_cfg_getstr(cfg, CFG_NUMTRIES); - if ((numtries == NULL) || ((num = atoi(numtries)) <= 0)) { - return MAX_PASSWORD_ATTEMPTS; - } else if (strcmp(numtries, "unlimited")) { + if (numtries != NULL && !strcmp(numtries, "unlimited")) { return INFINITE_ATTEMPTS; + } else if ((numtries == NULL) || ((num = atoi(numtries)) <= 0)) { + return MAX_PASSWORD_ATTEMPTS; } else { return num; }