From 30a37965dfab381bf01feafd7530157b48d75c9f Mon Sep 17 00:00:00 2001 From: AloneLiberty <111039319+AloneLiberty@users.noreply.github.com> Date: Tue, 25 Apr 2023 23:52:12 +0300 Subject: [PATCH] 1.2.1 - Fix memory leaks --- lib/nested/nested.c | 30 +++++++++++++++++++++++++++--- mifare_nested_i.h | 2 +- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lib/nested/nested.c b/lib/nested/nested.c index a8e54340328..08fb5af3ea1 100644 --- a/lib/nested/nested.c +++ b/lib/nested/nested.c @@ -228,7 +228,10 @@ struct nonce_info_static nested_static_nonce_attack( // Setup nfc poller nfc_activate(); - if(!furi_hal_nfc_activate_nfca(200, &cuid)) return r; + if(!furi_hal_nfc_activate_nfca(200, &cuid)) { + free(crypto); + return r; + } r.cuid = cuid; @@ -251,6 +254,7 @@ struct nonce_info_static nested_static_nonce_attack( mifare_sendcmd_short(crypto, tx_rx, true, 0x60 + (targetKeyType & 0x01), targetBlockNo); if(!success) { + free(crypto); return r; }; @@ -259,7 +263,10 @@ struct nonce_info_static nested_static_nonce_attack( nfc_activate(); - if(!furi_hal_nfc_activate_nfca(200, &cuid)) return r; + if(!furi_hal_nfc_activate_nfca(200, &cuid)) { + free(crypto); + return r; + } crypto1_reset(crypto); @@ -270,6 +277,8 @@ struct nonce_info_static nested_static_nonce_attack( success = mifare_sendcmd_short(crypto, tx_rx, true, 0x60 + (targetKeyType & 0x01), targetBlockNo); + free(crypto); + if(!success) { return r; }; @@ -334,6 +343,7 @@ uint32_t nested_calibrate_distance( } else { unsuccessful_tries++; if(unsuccessful_tries > 12) { + free(crypto); FURI_LOG_E( TAG, "Tag isn't vulnerable to nested attack (random numbers are not predictable)"); @@ -355,6 +365,8 @@ uint32_t nested_calibrate_distance( davg, collected); + free(crypto); + nfc_deactivate(); return davg; @@ -406,9 +418,12 @@ struct distance_info nested_calibrate_distance_info( } else { unsuccessful_tries++; if(unsuccessful_tries > 12) { + free(crypto); + FURI_LOG_E( TAG, "Tag isn't vulnerable to nested attack (random numbers are not predictable)"); + return r; } } @@ -423,6 +438,8 @@ struct distance_info nested_calibrate_distance_info( r.max_prng = dmax; r.mid_prng = davg; + free(crypto); + nfc_deactivate(); return r; @@ -521,6 +538,8 @@ struct nonce_info nested_attack( r.full = true; } + free(crypto); + nfc_deactivate(); return r; @@ -546,7 +565,10 @@ struct nonce_info_hard hard_nested_collect_nonces( for(uint32_t i = 0; i < 8; i++) { nfc_activate(); - if(!furi_hal_nfc_activate_nfca(200, &cuid)) return r; + if(!furi_hal_nfc_activate_nfca(200, &cuid)) { + free(crypto); + return r; + } r.cuid = cuid; @@ -597,6 +619,8 @@ struct nonce_info_hard hard_nested_collect_nonces( r.full = true; + free(crypto); + nfc_deactivate(); return r; diff --git a/mifare_nested_i.h b/mifare_nested_i.h index 44005457b7a..1a155923e51 100644 --- a/mifare_nested_i.h +++ b/mifare_nested_i.h @@ -19,7 +19,7 @@ #include #include "mifare_nested_icons.h" -#define NESTED_VERSION_APP "1.2.0" +#define NESTED_VERSION_APP "1.2.1" #define NESTED_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNested" #define NESTED_RECOVER_KEYS_GITHUB_LINK "https://github.com/AloneLiberty/FlipperNestedRecovery" #define NESTED_NONCE_FORMAT_VERSION "3"