diff --git a/app/src/parser.c b/app/src/parser.c index dfb87034..0048f4e2 100644 --- a/app/src/parser.c +++ b/app/src/parser.c @@ -447,6 +447,17 @@ __Z_INLINE parser_error_t parser_getTextualItem(const parser_context_t *ctx, container.screen.expert = false; CHECK_PARSER_ERR(parser_getScreenInfo(ctx, &container, displayIdx)) + if (container.screen.titlePtr != NULL && container.screen.contentPtr == NULL) {\ + if (!strncmp(container.screen.titlePtr, "Chain id", container.screen.titleLen)){ + if(!strncmp(container.screen.contentPtr, "0", container.screen.contentLen) || + !strncmp(container.screen.contentPtr, "1", container.screen.contentLen)) { + return parser_unexpected_chain; + } + } + } + + + if (!app_mode_expert()) { CHECK_PARSER_ERR(parser_getNextNonExpert(ctx, &container, displayIdx)) } diff --git a/app/src/tx_display.c b/app/src/tx_display.c index e1829da2..e220b981 100644 --- a/app/src/tx_display.c +++ b/app/src/tx_display.c @@ -131,6 +131,9 @@ __Z_INLINE parser_error_t calculate_is_default_chainid() { // If we don't match the default chainid, switch to expert mode display_cache.is_default_chain = true; zemu_log_stack("DEFAULT Chain "); + } else if (strcmp(outVal, "0") == 0 || strcmp(outVal, "1") == 0) { + zemu_log_stack("Not Allowed chain"); + return parser_unexpected_chain; } else { zemu_log_stack("Chain is NOT DEFAULT"); } diff --git a/tests/tx_parse.cpp b/tests/tx_parse.cpp index 94dba4e9..f4c7b2aa 100644 --- a/tests/tx_parse.cpp +++ b/tests/tx_parse.cpp @@ -127,7 +127,7 @@ namespace { } TEST(TxParse, Count_Minimal) { - auto transaction = R"({"account_number":"0"})"; + auto transaction = R"({"account_number":"3"})"; parser_tx_obj.tx_json.tx = transaction; parser_tx_obj.tx_json.flags.cache_valid = false; @@ -140,6 +140,19 @@ namespace { EXPECT_EQ(1, numItems) << "Wrong number of items"; } + TEST(TxParse, Tx_Chain_not_Allowed) { + auto transaction = R"({"account_number":"0","chain_id":"0","fee":{"amount":[{"amount":"5","denom":"photon"}],"gas":"10000"},"memo":"testmemo","msgs":[{"inputs":[{"address":"cosmosaccaddr1d9h8qat5e4ehc5","coins":[{"amount":"10","denom":"atom"}]}],"outputs":[{"address":"cosmosaccaddr1da6hgur4wse3jx32","coins":[{"amount":"10","denom":"atom"}]}]}],"sequence":"1"})"; + + parser_tx_obj.tx_json.tx = transaction; + parser_tx_obj.tx_json.flags.cache_valid = false; + parser_error_t err = JSON_PARSE(&parser_tx_obj.tx_json.json, parser_tx_obj.tx_json.tx); + EXPECT_EQ(err, parser_ok); + + uint8_t numItems; + parser_error_t err2 = tx_display_numItems(&numItems); + EXPECT_EQ(err2, parser_unexpected_chain); + } + TEST(TxParse, Tx_Page_Count) { auto transaction = R"({"account_number":"0","chain_id":"test-chain-1","fee":{"amount":[{"amount":"5","denom":"photon"}],"gas":"10000"},"memo":"testmemo","msgs":[{"inputs":[{"address":"cosmosaccaddr1d9h8qat5e4ehc5","coins":[{"amount":"10","denom":"atom"}]}],"outputs":[{"address":"cosmosaccaddr1da6hgur4wse3jx32","coins":[{"amount":"10","denom":"atom"}]}]}],"sequence":"1"})";