LedgerHQ/ledger-live

[Bug]: incorrect offset in reading APDU answer of `GetVersion`

Closed this issue · 2 comments

Impacted Library name

No response

Impacted Library version

No response

Describe the bug

The parseGetVersionResponse function seems to be incorrectly updating the offset counter after reading the SE target id. I believe it is due to a copy paste error.

Earlier in the function the flags are parsed:

// flags. gives information about manager allowed in SE mode.
const flagsLength = data[i++];
let flags = data.slice(i, i + flagsLength);
i += flagsLength;

Later when parsing the SE target id (in case the target id corresponds to a bootloader one and it's either the new or old format but WE CAN'T know this is not documented), the offset counter is updated by the value of the length of the flags slice, not the length of the SE target id slice!

const part2Length = data[i++];
const part2 = data.slice(i, i + part2Length);
i += flagsLength;

In passing, please document your APDU protocol. This is really not a fun exercise to have to reverse-engineer it from the confusing Ledger Live codebase.

Expected behavior

I don't think this changes the behaviour but could lead to a pretty nasty bug should this function be updated in the future.

Additional context

No response

This issue is stale because it has been open 30 days with no activity. Remove stale label, comment, or consider closing it.