From d4cee7e65a4a3abf68380041a0bcd38075906f15 Mon Sep 17 00:00:00 2001 From: Ingo Franzki Date: Thu, 21 Nov 2019 15:57:09 +0100 Subject: [PATCH] zkey: Fix APQN checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An invalid APQN like '01.00xx' is not treated as invalid, but results in APQN '01.0000'. Fix the checking to treat such invalid APQNs as invalid. Signed-off-by: Ingo Franzki Reviewed-by: Harald Freudenberger Signed-off-by: Jan Höppner --- zkey/keystore.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/zkey/keystore.c b/zkey/keystore.c index af67721c..f253fc5d 100644 --- a/zkey/keystore.c +++ b/zkey/keystore.c @@ -1106,6 +1106,7 @@ static int _keystore_apqn_check(const char *apqn, bool remove, bool UNUSED(set), int rc, card, domain; regmatch_t pmatch[1]; regex_t reg_buf; + unsigned int num; *normalized = NULL; @@ -1120,7 +1121,9 @@ static int _keystore_apqn_check(const char *apqn, bool remove, bool UNUSED(set), goto out; } - if (sscanf(apqn, "%x.%x", &card, &domain) != 2) { + if (sscanf(apqn, "%x.%x%n", &card, &domain, &num) != 2 || + num != strlen(apqn) || card < 0 || card > 0xff || + domain < 0 || domain > 0xFFFF) { warnx("the APQN '%s' is not valid", apqn); rc = -EINVAL; goto out;