From b1eb10c8d3f19eb5def4b4e396fd43ff3f689ff6 Mon Sep 17 00:00:00 2001 From: merlokk <807634+merlokk@users.noreply.github.com> Date: Wed, 17 Oct 2018 18:02:24 +0300 Subject: [PATCH] added error handling in FIDOExchange --- client/cmdhffido.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/cmdhffido.c b/client/cmdhffido.c index 07de6af7..a89dca30 100644 --- a/client/cmdhffido.c +++ b/client/cmdhffido.c @@ -45,11 +45,18 @@ int FIDOSelect(bool ActivateField, bool LeaveFieldON, uint8_t *Result, size_t Ma int FIDOExchange(sAPDU apdu, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw) { int res = EMVExchange(true, apdu, Result, MaxResultLen, ResultLen, sw, NULL); + if (res == 5) // apdu result (sw) not a 0x9000 + res = 0; // software chaining - while ((*sw >> 8) == 0x61) { + while (!res && (*sw >> 8) == 0x61) { size_t oldlen = *ResultLen; - res = EMVExchange(true, (sAPDU){0x00, 0xC0, 0x00, 0x00, 0x00, NULL}, &Result[oldlen], MaxResultLen, ResultLen, sw, NULL); + res = EMVExchange(true, (sAPDU){0x00, 0xC0, 0x00, 0x00, 0x00, NULL}, &Result[oldlen], MaxResultLen - oldlen, ResultLen, sw, NULL); + if (res == 5) // apdu result (sw) not a 0x9000 + res = 0; + *ResultLen += oldlen; + if (*ResultLen > MaxResultLen) + return 100; } return res; }