From 494233d33b3a9d21da1bb0f1c59606820afe4691 Mon Sep 17 00:00:00 2001 From: Emmanuel Dreyfus Date: Thu, 27 Apr 2017 16:53:45 +0200 Subject: [PATCH] Do not fail crypto error without reporting Make sure last_pcd_error is set when failing on crypto errors. While there: - make sure warn()/warnx() are inside WITH_DEBUG, - set last_pcd_error and res before calling abort() - #include for abort() --- libfreefare/mifare_desfire_crypto.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libfreefare/mifare_desfire_crypto.c b/libfreefare/mifare_desfire_crypto.c index f42898a..98a9d68 100644 --- a/libfreefare/mifare_desfire_crypto.c +++ b/libfreefare/mifare_desfire_crypto.c @@ -56,6 +56,7 @@ #include #include +#include #include #include #include @@ -422,12 +423,13 @@ mifare_cryto_preprocess_data (FreefareTag tag, void *data, size_t *nbytes, off_t mifare_cypher_blocks_chained (tag, NULL, NULL, res + offset, *nbytes - offset, MCD_SEND, (AS_NEW == MIFARE_DESFIRE (tag)->authentication_scheme) ? MCO_ENCYPHER : MCO_DECYPHER); break; default: - warnx ("Unknown communication settings"); -#ifdef WITH_DEBUG - abort (); -#endif + MIFARE_DESFIRE (tag)->last_pcd_error = CRYPTO_ERROR; *nbytes = -1; res = NULL; +#ifdef WITH_DEBUG + warnx ("Unknown communication settings"); + abort (); +#endif break; } @@ -464,6 +466,7 @@ mifare_cryto_postprocess_data (FreefareTag tag, void *data, ssize_t *nbytes, int if (communication_settings & MAC_VERIFY) { *nbytes -= key_macing_length (key); if (*nbytes <= 0) { + MIFARE_DESFIRE (tag)->last_pcd_error = CRYPTO_ERROR; *nbytes = -1; res = NULL; #ifdef WITH_DEBUG @@ -499,6 +502,7 @@ mifare_cryto_postprocess_data (FreefareTag tag, void *data, ssize_t *nbytes, int break; if (communication_settings & CMAC_VERIFY) { if (*nbytes < 9) { + MIFARE_DESFIRE (tag)->last_pcd_error = CRYPTO_ERROR; *nbytes = -1; res = NULL; #ifdef WITH_DEBUG @@ -654,12 +658,13 @@ mifare_cryto_postprocess_data (FreefareTag tag, void *data, ssize_t *nbytes, int break; default: - warnx ("Unknown communication settings"); -#ifdef WITH_DEBUG - abort (); -#endif + MIFARE_DESFIRE (tag)->last_pcd_error = CRYPTO_ERROR; *nbytes = -1; res = NULL; +#ifdef WITH_DEBUG + warnx ("Unknown communication settings"); + abort (); +#endif break; }