Skip to content

Commit 5b277fe

Browse files
authored
Merge pull request #66 from oToToT/suica-fix
Avoid accessing uninitialized memory in Suica
2 parents 484aff2 + 136a9a0 commit 5b277fe

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

scenes/plugins/suica.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,6 @@ static NfcCommand suica_poller_callback(NfcGenericEvent event, void* context) {
308308
const uint16_t service_code[2] = {SERVICE_CODE_HISTORY_IN_LE, SERVICE_CODE_TAPS_LOG_IN_LE};
309309

310310
const FelicaPollerEvent* felica_event = event.event_data;
311-
FelicaPollerReadCommandResponse* rx_resp;
312-
rx_resp->SF1 = 0;
313-
rx_resp->SF2 = 0;
314-
uint8_t blocks[1] = {0x00};
315311
FelicaPoller* felica_poller = event.instance;
316312
const FelicaData* felica_data = nfc_poller_get_data(app->poller);
317313
FURI_LOG_I(TAG, "Poller set");
@@ -324,18 +320,16 @@ static NfcCommand suica_poller_callback(NfcGenericEvent event, void* context) {
324320
app->nfc_device, NfcProtocolFelica, nfc_poller_get_data(app->poller));
325321
furi_string_printf(parsed_data, "\e#Suica\n");
326322

327-
FelicaError error = FelicaErrorNone;
328-
int service_code_index = 0;
329323
// Authenticate with the card
330324
// Iterate through the two services
331-
while(service_code_index < 2 && error == FelicaErrorNone) {
325+
for (int service_code_index = 0; service_code_index < 2; service_code_index++) {
332326
furi_string_cat_printf(
333327
parsed_data, "%s: \n", suica_service_names[service_code_index]);
334-
rx_resp->SF1 = 0;
335-
rx_resp->SF2 = 0;
336-
blocks[0] = 0; // firmware api requires this to be a list
337-
while((rx_resp->SF1 + rx_resp->SF2) == 0 &&
338-
blocks[0] < SUICA_MAX_HISTORY_ENTRIES && error == FelicaErrorNone) {
328+
329+
FelicaError error = FelicaErrorNone;
330+
FelicaPollerReadCommandResponse* rx_resp;
331+
uint8_t blocks[1] = {0x00};
332+
do {
339333
uint8_t block_data[16] = {0};
340334
error = felica_poller_read_blocks(
341335
felica_poller, 1, blocks, service_code[service_code_index], &rx_resp);
@@ -360,8 +354,12 @@ static NfcCommand suica_poller_callback(NfcGenericEvent event, void* context) {
360354
model->size);
361355
suica_add_entry(model, block_data);
362356
}
357+
} while((rx_resp->SF1 + rx_resp->SF2) == 0 &&
358+
blocks[0] < SUICA_MAX_HISTORY_ENTRIES && error == FelicaErrorNone);
359+
360+
if (error != FelicaErrorNone) {
361+
break;
363362
}
364-
service_code_index++;
365363
}
366364
metroflip_app_blink_stop(app);
367365

0 commit comments

Comments
 (0)