Skip to content

Commit

Permalink
Merge pull request #630 from LedgerHQ/fix/apa/eip712_empty_array_trav…
Browse files Browse the repository at this point in the history
…ersal_end

Fix EIP-712 end of empty arrays traversal
  • Loading branch information
apaillier-ledger authored Aug 23, 2024
2 parents 055e0c0 + 2f13f4c commit 3ef1122
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions src_features/signMessageEIP712/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,10 @@ static bool array_depth_list_pop(void) {
*
* @param[in] skip_if_array skip if path is already pointing at an array
* @param[in] stop_at_array stop at the first downstream array
* @param[in] do_typehash if a typehash needs to be done when a new struct is encountered
* @return whether the path update worked or not
*/
static bool path_update(bool skip_if_array, bool stop_at_array) {
static bool path_update(bool skip_if_array, bool stop_at_array, bool do_typehash) {
uint8_t fields_count;
const void *struct_ptr;
const void *starting_field_ptr;
Expand Down Expand Up @@ -327,9 +328,7 @@ static bool path_update(bool skip_if_array, bool stop_at_array) {
return false;
}

// The only times they are both at false is if we are traversing an empty array,
// don't do a typehash in that case
if ((skip_if_array != false) || (stop_at_array != false)) {
if (do_typehash) {
// get the struct typehash
if (type_hash(typename, typename_len, hash) == false) {
return false;
Expand Down Expand Up @@ -399,7 +398,7 @@ bool path_set_root(const char *const struct_name, uint8_t name_length) {
struct_state = DEFINED;

// because the first field could be a struct type
path_update(true, true);
path_update(true, true, true);
return true;
}

Expand Down Expand Up @@ -467,7 +466,7 @@ bool path_new_array_depth(const uint8_t *const data, uint8_t length) {
}

array_size = *data;
if (!path_update(false, array_size > 0)) {
if (!path_update(false, array_size > 0, array_size > 0)) {
return false;
}
array_depth_count_bak = path_struct->array_depth_count;
Expand Down Expand Up @@ -583,7 +582,7 @@ static bool path_advance_in_array(void) {
*
* @return whether the advancement was successful or not
*/
bool path_advance(bool array_check) {
bool path_advance(bool do_typehash) {
bool end_reached;

do {
Expand All @@ -593,7 +592,7 @@ bool path_advance(bool array_check) {
end_reached = false;
}
} while (end_reached);
return path_update(array_check, array_check);
return path_update(true, true, do_typehash);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src_features/signMessageEIP712/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef struct {

bool path_set_root(const char *const struct_name, uint8_t length);
const void *path_get_field(void);
bool path_advance(bool array_check);
bool path_advance(bool do_typehash);
bool path_init(void);
void path_deinit(void);
bool path_new_array_depth(const uint8_t *const data, uint8_t length);
Expand Down

0 comments on commit 3ef1122

Please sign in to comment.