Skip to content

Commit

Permalink
1.2.1 - Fix memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
AloneLiberty committed Apr 25, 2023
1 parent a8f0a83 commit 30a3796
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions lib/nested/nested.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
};

Expand All @@ -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);

Expand All @@ -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;
};
Expand Down Expand Up @@ -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)");
Expand All @@ -355,6 +365,8 @@ uint32_t nested_calibrate_distance(
davg,
collected);

free(crypto);

nfc_deactivate();

return davg;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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;
Expand Down Expand Up @@ -521,6 +538,8 @@ struct nonce_info nested_attack(
r.full = true;
}

free(crypto);

nfc_deactivate();

return r;
Expand All @@ -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;

Expand Down Expand Up @@ -597,6 +619,8 @@ struct nonce_info_hard hard_nested_collect_nonces(

r.full = true;

free(crypto);

nfc_deactivate();

return r;
Expand Down
2 changes: 1 addition & 1 deletion mifare_nested_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <lib/nfc/nfc_device.h>
#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"
Expand Down

0 comments on commit 30a3796

Please sign in to comment.