obsidiansystems / ledger-app-tezos

Ledger app for Tezos
Apache License 2.0
102 stars 51 forks source link

Missing `state->address_step=3;` in `michelson_read_address`? #160

Open fishilico opened 3 years ago

fishilico commented 3 years ago

Hello, While reading the state machine in src/operations.c I am wondering how this code works: https://github.com/obsidiansystems/ledger-app-tezos/blob/58797b2f9606c5a30dd1ccc9e5b9962e45e10356/src/operations.c#L199-L213

More precisely after case 0: ... state->address_step=1; and case 1: ... state->address_step=2;, why is there no state->address_step=3; on line 209, at the end of case 2:? The case block "falls through" into case 3 and then the function returns in CALL_SUBPARSER (line 212). When I add some printf statements in this function to analyze where the flow goes, it seems that the "subparsing" goes back to line 207 instead of line 212 and that the code in lines 213-215 is never executed. Did I understand the code correctly or did I miss something?

mikereinhart commented 3 years ago

Thanks for opening this issue, this is indeed a bug!

Did you encounter this while attempting an operation with a Michelson address in binary format or were you inspecting code? The reason I ask - tezos-client only prepares addresses as ASCII so we aren't aware of a real world instance where this code is used.

As we think about the best solution for this, if the code is dead in practice since only ASCII is used, the best solution could be to remove it and avoid the unnecessary feature (and the testing challenges that come from not being able to create binary formatted addresses from tezos-client).

Additional feedback on how you encountered this will help us make the right decision here. This will most likely be done as part of a batch of changes, whenever that may be. Thanks again!

fishilico commented 3 years ago

Did you encounter this while attempting an operation with a Michelson address in binary format or were you inspecting code?

Thanks for your quick reply! I am working on a fuzzing+code coverage tool and wanted to test it on some Ledger Nano applications. I found this bug while investigating why some lines of code appeared to never be reached according to the code coverage report. So I do not know whether a real Tezos transaction runs the buggy code path.

nmm5055 commented 3 years ago

Hello, While reading the state machine in src/operations.c I am wondering how this code works:

https://github.com/obsidiansystems/ledger-app-tezos/blob/58797b2f9606c5a30dd1ccc9e5b9962e45e10356/src/operations.c#L199-L213

More precisely after case 0: ... state->address_step=1; and case 1: ... state->address_step=2;, why is there no state->address_step=3; on line 209, at the end of case 2:? The case block "falls through" into case 3 and then the function returns in CALL_SUBPARSER (line 212). When I add some printf statements in this function to analyze where the flow goes, it seems that the "subparsing" goes back to line 207 instead of line 212 and that the code in lines 213-215 is never executed. Did I understand the code correctly or did I miss something?

tz1dk5tsD3vr1ib7XY2CULdWa81vMBbVbjDj