Skip to content

Commit

Permalink
Audit related minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
relatko committed Jun 5, 2024
1 parent 0f7d03a commit b94d397
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/parser_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ parser_error_t json_matchToken(const parsed_json_t *parsedJson,
return PARSER_UNEXPECTED_TYPE;
}

if (token.end < token.start || strlen(expectedValue) != (size_t)(token.end - token.start)) {
if (token.end < token.start || strlen(expectedValue) != (size_t) (token.end - token.start)) {
return PARSER_UNEXPECTED_VALUE;
}

Expand All @@ -211,7 +211,7 @@ parser_error_t json_matchNull(const parsed_json_t *parsedJson, uint16_t tokenIdx
return PARSER_UNEXPECTED_TYPE;
}

if (token.end < token.start || 4 != (size_t)(token.end - token.start)) {
if (token.end < token.start || 4 != (size_t) (token.end - token.start)) {
return PARSER_UNEXPECTED_VALUE;
}

Expand Down Expand Up @@ -581,7 +581,7 @@ parser_error_t _countArgumentItems(const flow_argument_list_t *v,
void checkAddressUsedInTx() {
addressUsedInTx = 0;
uint16_t authCount = parser_tx_obj.authorizers.authorizer_count;
for (uint16_t i = 0; i < (uint16_t)(authCount + 2); i++) { //+2 for proposer and payer
for (uint16_t i = 0; i < (uint16_t) (authCount + 2); i++) { //+2 for proposer and payer
parser_context_t *ctx = NULL;
if (i > authCount) ctx = &parser_tx_obj.payer.ctx;
if (i == authCount) ctx = &parser_tx_obj.proposalKeyAddress.ctx;
Expand Down
6 changes: 6 additions & 0 deletions src/parser_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,9 @@ parser_error_t parser_getItem_internal(int8_t *displayIdx,
return PARSER_OK;
}
} else {
if (!app_mode_expert()) {
return PARSER_UNEXPECTED_ERROR;
}
// Arbitrary message signing
SCREEN(true) {
snprintf(outKey, outKeyLen, "Script hash");
Expand Down Expand Up @@ -812,6 +815,9 @@ parser_error_t parser_getItem_internal(int8_t *displayIdx,
return PARSER_OK;
}
for (size_t i = 0; i < parser_tx_obj.arguments.argCount; i++) {
if (!app_mode_expert()) {
return PARSER_UNEXPECTED_ERROR;
}
SCREEN(true) {
return parser_printArbitraryArgument(&parser_tx_obj.arguments,
i,
Expand Down
7 changes: 4 additions & 3 deletions unit-tests/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const char *token7b =
"fe314dba5363c81654595d64884b1ecad1512a64e65e020164\"}],"
"\"type\": \"Array\"}";

const char *dummy = "";
const char *token2c = "{\"value\":\"1\",\"type\":\"UInt8\"}";
const char *token3c = "{\"value\":\"2\",\"type\":\"UInt8\"}";
const char *token4c = "{\"value\":\"3\",\"type\":\"UInt8\"}";
Expand All @@ -94,7 +95,7 @@ flow_argument_list_t arg_list_b;
flow_argument_list_t arg_list_c;

void createArgList() {
const parser_context_t context0;
const parser_context_t context0 = {(const uint8_t *) dummy, strlen(dummy), 0};
const parser_context_t context2 = {(const uint8_t *) token2, strlen(token2), 0};
const parser_context_t context3 = {(const uint8_t *) token3, strlen(token3), 0};
const parser_context_t context4 = {(const uint8_t *) token4, strlen(token4), 0};
Expand All @@ -107,7 +108,7 @@ void createArgList() {
6};
memcpy(&arg_list, &new_arg_list, sizeof(arg_list));

const parser_context_t context0b;
const parser_context_t context0b = {(const uint8_t *) dummy, strlen(dummy), 0};
const parser_context_t context2b = {(const uint8_t *) token2b, strlen(token2b), 0};
const parser_context_t context3b = {(const uint8_t *) token3b, strlen(token3b), 0};
const parser_context_t context4b = {(const uint8_t *) token4b, strlen(token4b), 0};
Expand All @@ -120,7 +121,7 @@ void createArgList() {
6};
memcpy(&arg_list_b, &new_arg_list_b, sizeof(arg_list_b));

const parser_context_t context0c;
const parser_context_t context0c = {(const uint8_t *) dummy, strlen(dummy), 0};
const parser_context_t context2c = {(const uint8_t *) token2c, strlen(token2c), 0};
const parser_context_t context3c = {(const uint8_t *) token3c, strlen(token3c), 0};
const parser_context_t context4c = {(const uint8_t *) token4c, strlen(token4c), 0};
Expand Down

0 comments on commit b94d397

Please sign in to comment.