From 60921fe72946f66d28e10042e06fab218fc6e544 Mon Sep 17 00:00:00 2001 From: ftheirs Date: Fri, 26 Aug 2022 16:25:12 -0300 Subject: [PATCH 1/3] find command and operation by hash --- app/src/candid/candid_parser.c | 118 +++++++++++++++++++++++++++++---- app/src/candid/candid_types.h | 44 ++++++------ app/src/common/parser_common.h | 2 + app/src/parser.c | 8 +-- app/src/parser_impl.c | 12 ++-- tests/phase2.json | 16 +++++ 6 files changed, 157 insertions(+), 43 deletions(-) diff --git a/app/src/candid/candid_parser.c b/app/src/candid/candid_parser.c index 4b4ce15b..d26e3370 100644 --- a/app/src/candid/candid_parser.c +++ b/app/src/candid/candid_parser.c @@ -22,6 +22,45 @@ // Good reference: https://github.com/dfinity/agent-js/tree/main/packages/candid // https://github.com/dfinity/candid/blob/master/spec/Candid.md#deserialisation +static uint16_t table_entry_point = 0; + +typedef parser_error_t (*check_hash)(const uint64_t *hash, bool *found); + +parser_error_t check_hash_method(const uint64_t *hash, bool *found) { + switch (*hash) + { + case hash_command_Spawn: + case hash_command_Split: + case hash_command_Follow: + case hash_command_ClaimOrRefresh: + case hash_command_Configure: + case hash_command_RegisterVote: + case hash_command_Merge: + *found = true; + break; + } + + return parser_ok; +} + +parser_error_t check_hash_operation(const uint64_t *hash, bool *found) { + switch (*hash) + { + // case hash_operation_Invalid: + // case hash_operation_IncreaseDissolveDelay: + // case hash_operation_StartDissolving: + // case hash_operation_StopDissolving: + // case hash_operation_AddHotKey: + // case hash_operation_RemoveHotKey: + // case hash_operation_JoinCommunityFund: + case hash_operation_SetDissolvedTimestamp: + *found = true; + break; + } + + return parser_ok; +} + parser_error_t checkCandidMAGIC(parser_context_t *ctx) { // Check DIDL magic bytes if (ctx->bufferLen < 4) { @@ -256,11 +295,8 @@ parser_error_t findCandidFieldHash(__Z_UNUSED parser_context_t *_ctx, return parser_not_implemented; } -parser_error_t readCandidTypeTable_Item(parser_context_t *ctx, __Z_UNUSED uint64_t typeIdx) { - int64_t ty; - CHECK_PARSER_ERR(readCandidType(ctx, &ty)) - - switch (ty) { +parser_error_t readCandidTypeTable_Item(parser_context_t *ctx, const int64_t *type, __Z_UNUSED uint64_t typeIdx) { + switch (*type) { case Opt: { zemu_log_stack("readCandidTypeTable::Opt"); CHECK_PARSER_ERR(readCandidTypeTable_Opt(ctx)) @@ -313,6 +349,15 @@ parser_error_t readCandidTypeTable_Item(parser_context_t *ctx, __Z_UNUSED uint64 return parser_ok; } +parser_error_t getNextType(parser_context_t *ctx, const IDLTypes_e type, int64_t *ty, const uint64_t itemIdx) { + CHECK_PARSER_ERR(readCandidType(ctx, ty)) + if (type == *ty) { + return parser_ok; + } + CHECK_PARSER_ERR(readCandidTypeTable_Item(ctx, ty, itemIdx)) + return parser_ok; +} + parser_error_t readCandidTypeTable(parser_context_t *ctx) { ctx->tx_obj->candid_typetableSize = 0; CHECK_PARSER_ERR(readCandidLEB128(ctx, &ctx->tx_obj->candid_typetableSize)) @@ -321,8 +366,11 @@ parser_error_t readCandidTypeTable(parser_context_t *ctx) { return parser_value_out_of_range; } + table_entry_point = ctx->offset; + int64_t type = 0; for (uint64_t itemIdx = 0; itemIdx < ctx->tx_obj->candid_typetableSize; itemIdx++) { - CHECK_PARSER_ERR(readCandidTypeTable_Item(ctx, itemIdx)) + CHECK_PARSER_ERR(readCandidType(ctx, &type)) + CHECK_PARSER_ERR(readCandidTypeTable_Item(ctx, &type, itemIdx)) } return parser_ok; @@ -349,12 +397,51 @@ parser_error_t readCandidHeader(parser_context_t *ctx) { ctx.offset = 0; \ ctx.tx_obj = __TX; + +parser_error_t findHash(parser_context_t *ctx, check_hash check_function, + const uint8_t variant, uint64_t *hash) { + ctx->offset = table_entry_point; + + int64_t type = 0; + bool found = false; + + for (uint64_t itemIdx = 0; itemIdx < ctx->tx_obj->candid_typetableSize; itemIdx++) { + CHECK_PARSER_ERR(getNextType(ctx, Variant, &type, itemIdx)) + if (type == Variant) { + uint64_t objectLength; + CHECK_PARSER_ERR(readCandidLEB128(ctx, &objectLength)) + + for (uint64_t i = 0; i < objectLength; i++) { + int64_t dummyType; + CHECK_PARSER_ERR(readCandidLEB128(ctx, hash)) + if (i == variant) { + CHECK_PARSER_ERR(check_function(hash, &found)) + } + if(found) { + return parser_ok; + } + + CHECK_PARSER_ERR(readCandidType(ctx, &dummyType)) + } + } + } + return parser_type_not_found; +} + +parser_error_t getHash(parser_context_t *ctx, check_hash check_function, + const uint8_t variant, uint64_t *hash) { + const uint16_t start = ctx->offset; + *hash = 0; + parser_error_t err = findHash(ctx, check_function, variant, hash); + ctx->offset = start; + return err; +} + parser_error_t readCandidManageNeuron(parser_tx_t *tx, const uint8_t *input, uint16_t inputSize) { CREATE_CTX(ctx, tx, input, inputSize) CHECK_PARSER_ERR(readCandidHeader(&ctx)) - /// - CHECK_PARSER_ERR(readAndCheckType(&ctx, 65)) + CHECK_PARSER_ERR(readAndCheckType(&ctx, (tx->candid_typetableSize - 1))) candid_ManageNeuron_t *val = &tx->tx_fields.call.data.candid_manageNeuron; // Now read @@ -366,13 +453,14 @@ parser_error_t readCandidManageNeuron(parser_tx_t *tx, const uint8_t *input, uin CHECK_PARSER_ERR(readCandidByte(&ctx, &val->has_command)) if (val->has_command) { CHECK_PARSER_ERR(readCandidNat(&ctx, &val->command.variant)) + CHECK_PARSER_ERR(getHash(&ctx, check_hash_method, val->command.variant, &val->command.hash)) - switch (val->command.variant) { - case command_Split: { + switch (val->command.hash) { + case hash_command_Split: { CHECK_PARSER_ERR(readCandidNat64(&ctx, &val->command.split.amount_e8s)) break; } - case command_Merge: { + case hash_command_Merge: { CHECK_PARSER_ERR(readCandidByte(&ctx, &val->command.merge.has_source)) if (!val->command.merge.has_source) { // https://github.com/Zondax/ledger-icp/issues/149 @@ -382,7 +470,7 @@ parser_error_t readCandidManageNeuron(parser_tx_t *tx, const uint8_t *input, uin CHECK_PARSER_ERR(readCandidNat64(&ctx, &val->command.merge.source.id)) break; } - case command_Configure: { + case hash_command_Configure: { CHECK_PARSER_ERR(readCandidByte(&ctx, &val->command.configure.has_operation)) if (!val->command.configure.has_operation) { return parser_unexpected_value; @@ -390,8 +478,10 @@ parser_error_t readCandidManageNeuron(parser_tx_t *tx, const uint8_t *input, uin candid_Operation_t *operation = &val->command.configure.operation; CHECK_PARSER_ERR(readCandidWhichVariant(&ctx, &operation->which)) - switch (val->command.configure.operation.which) { - case operation_SetDissolvedTimestamp: { + CHECK_PARSER_ERR(getHash(&ctx, check_hash_operation, operation->which, &operation->hash)) + + switch (operation->hash) { + case hash_operation_SetDissolvedTimestamp:{ CHECK_PARSER_ERR(readCandidNat64(&ctx, &operation->setDissolveTimestamp.dissolve_timestamp_seconds)) diff --git a/app/src/candid/candid_types.h b/app/src/candid/candid_types.h index d5dbf9b8..a63622e0 100644 --- a/app/src/candid/candid_types.h +++ b/app/src/candid/candid_types.h @@ -53,27 +53,31 @@ typedef enum { } IDLTypes_e; typedef enum { - command_Invalid = 0, - - command_Spawn = 0, - command_Split = 1, - command_Follow = 2, - command_ClaimOrRefresh = 3, - command_Configure = 4, - command_RegisterVote = 5, - command_Merge = 6, -} command_variant_e; + hash_command_Spawn = 345247259, + hash_command_Split = 345791162, + hash_command_Follow = 774571409, + hash_command_ClaimOrRefresh = 1349619708, + hash_command_Configure = 1647237574, + hash_command_RegisterVote = 2455066893, + hash_command_Merge = 2566132376, + hash_command_DisburseToNeuron = 2803800337, + hash_command_MakeProposal = 3217030240, + hash_command_MergeMaturity = 3865893897, + hash_command_Disburse = 4121967011, + } command_variant_hash_e; typedef enum { - operation_Invalid = 0, - operation_IncreaseDissolveDelay = 1, - operation_StartDissolving = 2, - operation_StopDissolving = 3, - operation_AddHotKey = 4, - operation_RemoveHotKey = 5, - operation_SetDissolvedTimestamp = 6, - operation_JoinCommunityFund = 7, -} operation_variant_e; + //Check these hashes + hash_operation_Invalid = 971299358, + hash_operation_IncreaseDissolveDelay = 628424947, + hash_operation_StartDissolving = 1954991536, + hash_operation_StopDissolving = 1977744848, + hash_operation_AddHotKey = 2143729936, + hash_operation_RemoveHotKey = 3248805476, + hash_operation_JoinCommunityFund = 45994902, + + hash_operation_SetDissolvedTimestamp = 3913126211, +} operation_variant_hash_e; typedef struct { uint64_t len; @@ -90,6 +94,7 @@ typedef struct { typedef struct { uint64_t which; + uint64_t hash; union { candid_SetDissolveTimestamp_t setDissolveTimestamp; }; @@ -111,6 +116,7 @@ typedef struct { typedef struct { uint64_t variant; + uint64_t hash; union { candid_Split_t split; candid_Merge_t merge; diff --git a/app/src/common/parser_common.h b/app/src/common/parser_common.h index 14c2b180..1a079a32 100644 --- a/app/src/common/parser_common.h +++ b/app/src/common/parser_common.h @@ -60,6 +60,8 @@ typedef enum { // Required fields parser_required_nonce, parser_required_method, + // Special codes + parser_type_not_found, } parser_error_t; typedef struct { diff --git a/app/src/parser.c b/app/src/parser.c index 822d361a..dd7ebfea 100644 --- a/app/src/parser.c +++ b/app/src/parser.c @@ -605,9 +605,9 @@ parser_error_t parser_getItemSetDissolveTimestamp(uint8_t displayIdx, uint8_t pageIdx, uint8_t *pageCount) { candid_ManageNeuron_t *fields = &parser_tx_obj.tx_fields.call.data.candid_manageNeuron; - PARSER_ASSERT_OR_ERROR(fields->command.variant == command_Configure, parser_unexpected_value) + PARSER_ASSERT_OR_ERROR(fields->command.hash == hash_command_Configure, parser_unexpected_value) PARSER_ASSERT_OR_ERROR(fields->command.configure.has_operation, parser_unexpected_value) - PARSER_ASSERT_OR_ERROR(fields->command.configure.operation.which == operation_SetDissolvedTimestamp, + PARSER_ASSERT_OR_ERROR(fields->command.configure.operation.hash == hash_operation_SetDissolvedTimestamp, parser_unexpected_value) if (displayIdx == 0) { @@ -713,7 +713,7 @@ parser_error_t parser_getItemSplit(uint8_t displayIdx, uint8_t pageIdx, uint8_t *pageCount) { candid_ManageNeuron_t *fields = &parser_tx_obj.tx_fields.call.data.candid_manageNeuron; - PARSER_ASSERT_OR_ERROR(fields->command.variant == command_Split, parser_unexpected_value) + PARSER_ASSERT_OR_ERROR(fields->command.hash == hash_command_Split, parser_unexpected_value) if (displayIdx == 0) { snprintf(outKey, outKeyLen, "Transaction type"); @@ -750,7 +750,7 @@ parser_error_t parser_getItemMerge(uint8_t displayIdx, uint8_t pageIdx, uint8_t *pageCount) { candid_ManageNeuron_t *fields = &parser_tx_obj.tx_fields.call.data.candid_manageNeuron; - PARSER_ASSERT_OR_ERROR(fields->command.variant == command_Merge, parser_unexpected_value) + PARSER_ASSERT_OR_ERROR(fields->command.hash == hash_command_Merge, parser_unexpected_value) if (displayIdx == 0) { snprintf(outKey, outKeyLen, "Transaction type"); diff --git a/app/src/parser_impl.c b/app/src/parser_impl.c index 1c2a262f..492691fb 100644 --- a/app/src/parser_impl.c +++ b/app/src/parser_impl.c @@ -295,19 +295,19 @@ parser_error_t getManageNeuronType(const parser_tx_t *v, manageNeuron_e *mn_type } const candid_Command_t *command = &v->tx_fields.call.data.candid_manageNeuron.command; - switch (command->variant) { - case command_Split: + switch (command->hash) { + case hash_command_Split: *mn_type = Split; return parser_ok; - case command_Merge: + case hash_command_Merge: *mn_type = Merge; return parser_ok; - case command_Configure: { + case hash_command_Configure: { if (!command->configure.has_operation) { return parser_unexpected_value; } - switch (command->configure.operation.which) { - case operation_SetDissolvedTimestamp: + switch (command->configure.operation.hash) { + case hash_operation_SetDissolvedTimestamp: *mn_type = Configure_SetDissolvedTimestamp; break; default: diff --git a/tests/phase2.json b/tests/phase2.json index e9d7dd15..a71b7198 100644 --- a/tests/phase2.json +++ b/tests/phase2.json @@ -171,5 +171,21 @@ ], "timestamp": 4102444799, "valid": true + }, + { + "index": 17, + "name": "Merge Neuron", + "blob": "d9d9f7a167636f6e74656e74a76361726759037d4449444c496c01dbb701786e006e796e686e786c03bc949d820302dbe2be950903ef9999fe09046c01b9ef938008786d006c02afa3bda10175c2cee0d80c076c006c029cb1fa2503ba89e5c204786b039ef5cc0f099992ccd0010adae1c99903786e0b6c01d7ab010c6c01f6b0989a08036c018eddc3a60d036c018dc3b2b303796c01c88ecad50a786b0896a7f7150ef381d4ab020fb09b9ba40709d0fb87af070990f29afe0710e4ac938d0c09f7aacfd80d09c3a2f6c90e116e126c01a78882820a136c02ea99cff20475b2b8d4960b016c01c38fbbd10b016c05f5bbe3900178d2bbf0d9017eb9ef93800878dbe2be950903ef9999fe09786c04efd6e4027198abec810119b6f798b201c500a696a48708716e716c02cbe4fdc70471fc91f4f805196e1a6c02dbb70101bac7a7fa0d1b6c01b99d9da50b796d7b6c01cedfa0a8041e6e1f6c01e0a9b302786e216c02a9ddf49b0720d8a38ca80d226b0b9b9cd0a40105bab5f1a40106918bacf10208fc9fc683050dc6b3bb9106148db2d592091598a5d0c7091691b2fab80a17e0f8fffd0b1889b8b3b30e1da3f3c0ad0f236e246b02cd8e8eb9041ecebee1d308006e266c03dbb70101cbe2b58b0825f1bb8b880d276c02e4d7bee905758effd6e90e1e6c02dbb701039df1afe707206e2a6c01f5bbe39001786c01a9ddf49b07206b02fdf59aec0b2ce3b586ff0c2d6e2e6c03ce9ca6ce012bf382ccb3072fb9ef938008786c02f9889a5778b2cc99e705786e316c01edbb85f901326e336c02cfbe93a40434c796cdbe0b036c01c2cee0d80c076c02007501366d376c0184aead33386e7e6d306c02f8b9b6c9043aa4ccf7dd0a3b6c089eb493cf0378befa8dd40479be8fe6e30478ce89be97067886f998bc0978c5cae3d40a7893a190e00c78f5e1d0e70d786d686c018594e2c50b3e6b02bf80e42b2ac6a6e4b90a2a6ec0006c01f0a2cabb0bc1006c0196bdb4e904716b0b93a7e09d021cd881c9c40328d69ce79d0a2982ffcfaa0c309dfa94a40d35e3c3c5990e39b1a5aea10e3cf5d9d7a50e3dfad5ddf40e3fdb9cebf70ec200d6f4c7ff0fc3006ec4006b0b9b9cd0a40105bab5f1a40106918bacf10208fc9fc683050dc6b3bb9106148db2d592091598a5d0c7091691b2fab80a17e0f8fffd0b1889b8b3b30e1da3f3c0ad0f236ec6006c03dbb70101cbe2b58b08c700f1bb8b880d2701c80001e2c738c140a0c107010601e787ac3d293afcf2006b63616e69737465725f69644a000000000000000101016e696e67726573735f6578706972791b170dabb81dddfa406b6d6574686f645f6e616d656d6d616e6167655f6e6575726f6e656e6f6e63655000000182c5975261ca758b1f999544eb6c726571756573745f747970656463616c6c6673656e646572581df1305df1b074e88adb99dc2f56f12d63208165f24dea7e60ae6cf6cf02", + "output": [ + "0 | Transaction type : Merge Neuron", + "1 | Neuron ID : 17508933400112433127", + "2 | Into Neuron ID : 558904028750727138" + ], + "output_expert": [ + "0 | Transaction type : Merge Neuron", + "1 | Neuron ID : 17508933400112433127", + "2 | Into Neuron ID : 558904028750727138" + ], + "valid": true } ] From 2a50620ca5dc459662577e66bacf2ba27f676739 Mon Sep 17 00:00:00 2001 From: ftheirs Date: Fri, 26 Aug 2022 16:53:37 -0300 Subject: [PATCH 2/3] bump version & snapshots --- app/Makefile | 6 +----- app/Makefile.version | 6 ++++++ tests_zemu/snapshots/s-mainmenu/00004.png | Bin 418 -> 419 bytes tests_zemu/snapshots/s-mainmenu/00010.png | Bin 418 -> 419 bytes tests_zemu/snapshots/sp-mainmenu/00004.png | Bin 363 -> 355 bytes tests_zemu/snapshots/sp-mainmenu/00010.png | Bin 363 -> 355 bytes tests_zemu/snapshots/x-mainmenu/00004.png | Bin 363 -> 355 bytes tests_zemu/snapshots/x-mainmenu/00010.png | Bin 363 -> 355 bytes 8 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 app/Makefile.version diff --git a/app/Makefile b/app/Makefile index f54ce933..4282e77c 100755 --- a/app/Makefile +++ b/app/Makefile @@ -40,8 +40,6 @@ all: bin/app.elf include $(BOLOS_SDK)/Makefile.defines -#DEFINES += APP_SECRET_MODE_ENABLED - $(info ************ TARGET_NAME = [$(TARGET_NAME)]) ifeq ($(APP_TESTING),1) @@ -54,9 +52,7 @@ ifndef COIN COIN=ICP endif -APPVERSION_M=2 -APPVERSION_N=1 -APPVERSION_P=0 +include $(CURDIR)/Makefile.version $(info COIN = [$(COIN)]) diff --git a/app/Makefile.version b/app/Makefile.version new file mode 100644 index 00000000..3e5fc4af --- /dev/null +++ b/app/Makefile.version @@ -0,0 +1,6 @@ +# This is the major version of this release +APPVERSION_M=2 +# This is the minor version of this release +APPVERSION_N=1 +# This is the patch version of this release +APPVERSION_P=1 diff --git a/tests_zemu/snapshots/s-mainmenu/00004.png b/tests_zemu/snapshots/s-mainmenu/00004.png index 9f85b8129f218a7cf5f7e36a4be03bd2a4e3fe9e..0bf1cff1e2c0a6451e463e5744602ab25b41f3e4 100644 GIT binary patch delta 393 zcmV;40e1eP1ET|wB!6m2L_t(|ob8#xa>F1DMCDHN{~zpwbD+^ELK5J_rog_F#|Yxt z1px{X0001RA;(U~ZajZD)D-;o{(wfdNAEBAGF=Ujb2%w{?6f`p-t&VBAYlUs$Tza% zzc=is+b^?}QduG+!*Gl@g6fq#7=&9^K$?y8OA%1EO1cy6s708O78}6o9TfWIag)oDp=2KjtT=*ThRl; zX4^v2GgGYP6n`YEG-Oo*R6za6L6=~_!4IH`mQsY7cD#a2<$x6K;lY5jq`t;lP;g@^ z_EIIx;>mRZ_35UYuv{PYc_VOWqH9OLax^nVDnCtc113r)=eV~R7nju%#oF9l)NR5S nA~$7WtD@eT7=KE4rq2NHzSl2AeWbD~ zpuSB8r689>#ld-FOnc5UfYnhCDK%MdnC!I_w|axHbd5SL1x=6h4X7jpi2fBN1FU%G z!;I3}Y6pqpf$dFZfV#*q)`4V#gUVi%o}Vgx8o+%;4~iqNRhc;o)-#JyVSwsudO+B0 zJtRFd#XP4VS%0OWQYAnQ=wG=q#ab{g6UD@N47JjZYVTB}X`8j66$b%v)`BWGrsgbF z!fc*g=h$6Nxe3cq?GM;F?iS<9(M<3hvXjvU%#mj*oLh{mm(>!@+T6A1+k_9w59+gw mt46K9@Bjb+004kcJOS{Tz#K+%CM5s>002ovPDHLkU;%>dmar-S diff --git a/tests_zemu/snapshots/s-mainmenu/00010.png b/tests_zemu/snapshots/s-mainmenu/00010.png index 9f85b8129f218a7cf5f7e36a4be03bd2a4e3fe9e..0bf1cff1e2c0a6451e463e5744602ab25b41f3e4 100644 GIT binary patch delta 393 zcmV;40e1eP1ET|wB!6m2L_t(|ob8#xa>F1DMCDHN{~zpwbD+^ELK5J_rog_F#|Yxt z1px{X0001RA;(U~ZajZD)D-;o{(wfdNAEBAGF=Ujb2%w{?6f`p-t&VBAYlUs$Tza% zzc=is+b^?}QduG+!*Gl@g6fq#7=&9^K$?y8OA%1EO1cy6s708O78}6o9TfWIag)oDp=2KjtT=*ThRl; zX4^v2GgGYP6n`YEG-Oo*R6za6L6=~_!4IH`mQsY7cD#a2<$x6K;lY5jq`t;lP;g@^ z_EIIx;>mRZ_35UYuv{PYc_VOWqH9OLax^nVDnCtc113r)=eV~R7nju%#oF9l)NR5S nA~$7WtD@eT7=KE4rq2NHzSl2AeWbD~ zpuSB8r689>#ld-FOnc5UfYnhCDK%MdnC!I_w|axHbd5SL1x=6h4X7jpi2fBN1FU%G z!;I3}Y6pqpf$dFZfV#*q)`4V#gUVi%o}Vgx8o+%;4~iqNRhc;o)-#JyVSwsudO+B0 zJtRFd#XP4VS%0OWQYAnQ=wG=q#ab{g6UD@N47JjZYVTB}X`8j66$b%v)`BWGrsgbF z!fc*g=h$6Nxe3cq?GM;F?iS<9(M<3hvXjvU%#mj*oLh{mm(>!@+T6A1+k_9w59+gw mt46K9@Bjb+004kcJOS{Tz#K+%CM5s>002ovPDHLkU;%>dmar-S diff --git a/tests_zemu/snapshots/sp-mainmenu/00004.png b/tests_zemu/snapshots/sp-mainmenu/00004.png index 334357ed3bf3396aa3b36eb4cf02bebb53429da9..791d8a1d3fc88564b0fe8874b7610e788ef44f76 100644 GIT binary patch delta 328 zcmaFO^q6UaO1+k+i(^Q|oVPa;`3@=Yv?ZF{Yxym|viu|a#02(Kzu42C?DmVXasTX+ zo+QM806R1U1t-4!I=w&Y=;3On{Zop+%{z4bk=TOR)2fkzCoQLct6FHaWEsy^=i8U~ zdIC1={?76%YfA2>mwUBb-x^mnNrh&8m>((s@IQCGhWDn}scv^NH|JbkCC}S4t@>#^ zL$mBmtvgKo`=Z$|M0uUn z{$4Iwr1p1mAhZ9TR-2Eq-?sFAe`eIr{DxU3dADS)`mR0i44t>%-6!gDr2dfB`plYR zuln|XP!@Y2)$V9x?W)u8uI delta 336 zcmaFN^qOgcO1+V%i(^Q|oVPa<`I;4Y+7h?DQM>csWAEv@2^0AiT5Z4Sbnm&iqu~>6 zt7V#u3~Ob2~mRON{?L=bxZ+H>8Q&vS@ksMY=lw+g+ZFkGpDhm7H74hnFMjK?{Ce%#3vaK_O?>~RmdKI;Vst00?=Wxc~qF diff --git a/tests_zemu/snapshots/sp-mainmenu/00010.png b/tests_zemu/snapshots/sp-mainmenu/00010.png index 334357ed3bf3396aa3b36eb4cf02bebb53429da9..791d8a1d3fc88564b0fe8874b7610e788ef44f76 100644 GIT binary patch delta 328 zcmaFO^q6UaO1+k+i(^Q|oVPa;`3@=Yv?ZF{Yxym|viu|a#02(Kzu42C?DmVXasTX+ zo+QM806R1U1t-4!I=w&Y=;3On{Zop+%{z4bk=TOR)2fkzCoQLct6FHaWEsy^=i8U~ zdIC1={?76%YfA2>mwUBb-x^mnNrh&8m>((s@IQCGhWDn}scv^NH|JbkCC}S4t@>#^ zL$mBmtvgKo`=Z$|M0uUn z{$4Iwr1p1mAhZ9TR-2Eq-?sFAe`eIr{DxU3dADS)`mR0i44t>%-6!gDr2dfB`plYR zuln|XP!@Y2)$V9x?W)u8uI delta 336 zcmaFN^qOgcO1+V%i(^Q|oVPa<`I;4Y+7h?DQM>csWAEv@2^0AiT5Z4Sbnm&iqu~>6 zt7V#u3~Ob2~mRON{?L=bxZ+H>8Q&vS@ksMY=lw+g+ZFkGpDhm7H74hnFMjK?{Ce%#3vaK_O?>~RmdKI;Vst00?=Wxc~qF diff --git a/tests_zemu/snapshots/x-mainmenu/00004.png b/tests_zemu/snapshots/x-mainmenu/00004.png index 334357ed3bf3396aa3b36eb4cf02bebb53429da9..791d8a1d3fc88564b0fe8874b7610e788ef44f76 100644 GIT binary patch delta 328 zcmaFO^q6UaO1+k+i(^Q|oVPa;`3@=Yv?ZF{Yxym|viu|a#02(Kzu42C?DmVXasTX+ zo+QM806R1U1t-4!I=w&Y=;3On{Zop+%{z4bk=TOR)2fkzCoQLct6FHaWEsy^=i8U~ zdIC1={?76%YfA2>mwUBb-x^mnNrh&8m>((s@IQCGhWDn}scv^NH|JbkCC}S4t@>#^ zL$mBmtvgKo`=Z$|M0uUn z{$4Iwr1p1mAhZ9TR-2Eq-?sFAe`eIr{DxU3dADS)`mR0i44t>%-6!gDr2dfB`plYR zuln|XP!@Y2)$V9x?W)u8uI delta 336 zcmaFN^qOgcO1+V%i(^Q|oVPa<`I;4Y+7h?DQM>csWAEv@2^0AiT5Z4Sbnm&iqu~>6 zt7V#u3~Ob2~mRON{?L=bxZ+H>8Q&vS@ksMY=lw+g+ZFkGpDhm7H74hnFMjK?{Ce%#3vaK_O?>~RmdKI;Vst00?=Wxc~qF diff --git a/tests_zemu/snapshots/x-mainmenu/00010.png b/tests_zemu/snapshots/x-mainmenu/00010.png index 334357ed3bf3396aa3b36eb4cf02bebb53429da9..791d8a1d3fc88564b0fe8874b7610e788ef44f76 100644 GIT binary patch delta 328 zcmaFO^q6UaO1+k+i(^Q|oVPa;`3@=Yv?ZF{Yxym|viu|a#02(Kzu42C?DmVXasTX+ zo+QM806R1U1t-4!I=w&Y=;3On{Zop+%{z4bk=TOR)2fkzCoQLct6FHaWEsy^=i8U~ zdIC1={?76%YfA2>mwUBb-x^mnNrh&8m>((s@IQCGhWDn}scv^NH|JbkCC}S4t@>#^ zL$mBmtvgKo`=Z$|M0uUn z{$4Iwr1p1mAhZ9TR-2Eq-?sFAe`eIr{DxU3dADS)`mR0i44t>%-6!gDr2dfB`plYR zuln|XP!@Y2)$V9x?W)u8uI delta 336 zcmaFN^qOgcO1+V%i(^Q|oVPa<`I;4Y+7h?DQM>csWAEv@2^0AiT5Z4Sbnm&iqu~>6 zt7V#u3~Ob2~mRON{?L=bxZ+H>8Q&vS@ksMY=lw+g+ZFkGpDhm7H74hnFMjK?{Ce%#3vaK_O?>~RmdKI;Vst00?=Wxc~qF From 631a11167ebae79c8fad1fb14b3489238f11a290 Mon Sep 17 00:00:00 2001 From: ftheirs Date: Tue, 30 Aug 2022 22:40:22 -0300 Subject: [PATCH 3/3] add null verification --- app/src/candid/candid_parser.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/candid/candid_parser.c b/app/src/candid/candid_parser.c index d26e3370..cf151326 100644 --- a/app/src/candid/candid_parser.c +++ b/app/src/candid/candid_parser.c @@ -27,6 +27,11 @@ static uint16_t table_entry_point = 0; typedef parser_error_t (*check_hash)(const uint64_t *hash, bool *found); parser_error_t check_hash_method(const uint64_t *hash, bool *found) { + if(found == NULL || hash == NULL) { + return parser_unexpected_value; + } + *found = false; + switch (*hash) { case hash_command_Spawn: @@ -44,6 +49,11 @@ parser_error_t check_hash_method(const uint64_t *hash, bool *found) { } parser_error_t check_hash_operation(const uint64_t *hash, bool *found) { + if(found == NULL || hash == NULL) { + return parser_unexpected_value; + } + *found = false; + switch (*hash) { // case hash_operation_Invalid: @@ -350,6 +360,10 @@ parser_error_t readCandidTypeTable_Item(parser_context_t *ctx, const int64_t *ty } parser_error_t getNextType(parser_context_t *ctx, const IDLTypes_e type, int64_t *ty, const uint64_t itemIdx) { + if(ty == NULL || ctx == NULL) { + return parser_unexpected_value; + } + CHECK_PARSER_ERR(readCandidType(ctx, ty)) if (type == *ty) { return parser_ok; @@ -400,6 +414,9 @@ parser_error_t readCandidHeader(parser_context_t *ctx) { parser_error_t findHash(parser_context_t *ctx, check_hash check_function, const uint8_t variant, uint64_t *hash) { + if(ctx == NULL || hash == NULL || check_function == NULL) { + return parser_unexpected_value; + } ctx->offset = table_entry_point; int64_t type = 0;