@@ -411,19 +411,25 @@ static bool path_update(bool skip_if_array, bool stop_at_array, bool do_typehash
411411 * @return boolean indicating if it was successful or not
412412 */
413413bool path_set_root (const char * struct_name , uint8_t name_length ) {
414+ const s_struct_712 * new_root ;
414415 uint8_t hash [KECCAK256_HASH_BYTESIZE ];
415416
416417 if (path_struct == NULL ) {
417418 apdu_response_code = SWO_INCORRECT_DATA ;
418419 return false;
419420 }
420421
421- if ((path_struct -> root_struct = get_structn (struct_name , name_length )) == NULL ) {
422+ if ((new_root = get_structn (struct_name , name_length )) == NULL ) {
422423 return false;
423424 }
425+ if (new_root == path_struct -> root_struct ) {
426+ PRINTF ("Error: already at that root struct!\n" );
427+ return false;
428+ }
429+ path_struct -> root_struct = new_root ;
424430
425431 if (path_struct -> root_struct == NULL ) {
426- PRINTF ("Struct name not found (" );
432+ PRINTF ("Error: struct name not found (" );
427433 for (int i = 0 ; i < name_length ; ++ i ) {
428434 PRINTF ("%c" , struct_name [i ]);
429435 }
@@ -451,8 +457,14 @@ bool path_set_root(const char *struct_name, uint8_t name_length) {
451457
452458 if ((name_length == strlen (DOMAIN_STRUCT_NAME )) &&
453459 (strncmp (struct_name , DOMAIN_STRUCT_NAME , name_length ) == 0 )) {
460+ if (path_struct -> root_type != ROOT_NONE ) {
461+ return false;
462+ }
454463 path_struct -> root_type = ROOT_DOMAIN ;
455464 } else {
465+ if (path_struct -> root_type != ROOT_DOMAIN ) {
466+ return false;
467+ }
456468 path_struct -> root_type = ROOT_MESSAGE ;
457469 }
458470
@@ -701,7 +713,7 @@ e_root_type path_get_root_type(void) {
701713 *
702714 * @return pointer to the root structure definition
703715 */
704- const void * path_get_root (void ) {
716+ const s_struct_712 * path_get_root (void ) {
705717 if (path_struct == NULL ) {
706718 return NULL ;
707719 }
0 commit comments