Skip to content

Commit 0346a2b

Browse files
authored
Merge pull request #179 from Zondax/check_principal
Allow bigger args for NanoS
2 parents 0ed809f + 665ac0f commit 0346a2b

File tree

30 files changed

+73
-17
lines changed

30 files changed

+73
-17
lines changed

.github/workflows/sonarcloud.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
name: SonarQube analyze
1515
runs-on: ubuntu-latest
1616
container:
17-
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
17+
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder@sha256:877adc3ff619222aaf03a490d546ea9001f02faa0c6ac7c06c876c99584f9cdb
1818
env:
1919
SONAR_SCANNER_VERSION: 4.7.0.2747
2020
SONAR_SERVER_URL: "https://sonarcloud.io"

app/Makefile.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ APPVERSION_M=2
33
# This is the minor version of this release
44
APPVERSION_N=1
55
# This is the patch version of this release
6-
APPVERSION_P=5
6+
APPVERSION_P=6

app/src/candid/candid_parser.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ const char *CustomTypeToString(uint64_t t) {
121121
return "?";
122122
}
123123
#else
124-
return "?"
124+
return "?";
125125
#endif
126126
}
127127

@@ -202,7 +202,7 @@ parser_error_t readCandidWhichVariant(parser_context_t *ctx, uint64_t *t) {
202202
parser_error_t readAndCheckRootType(parser_context_t *ctx) {
203203
int64_t tmpType = -1;
204204
CHECK_PARSER_ERR(readCandidType(ctx, &tmpType))
205-
if (tmpType < 0 || tmpType >= ctx->tx_obj->candid_typetableSize) {
205+
if (tmpType < 0 || (uint64_t) tmpType >= ctx->tx_obj->candid_typetableSize) {
206206
return parser_unexpected_type;
207207
}
208208

@@ -740,7 +740,7 @@ parser_error_t readCandidManageNeuron(parser_tx_t *tx, const uint8_t *input, uin
740740
CHECK_PARSER_ERR(readCandidWhichVariant(&ctx, &val->neuron_id_or_subaccount.which))
741741

742742
txn.element.implementation = savedElementImplementation;
743-
int64_t neuron_id_or_subaccount_hash = 0;
743+
uint64_t neuron_id_or_subaccount_hash = 0;
744744
CHECK_PARSER_ERR(getHash(&txn, val->neuron_id_or_subaccount.which, &neuron_id_or_subaccount_hash))
745745

746746
switch (neuron_id_or_subaccount_hash) {

app/src/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ parser_error_t parser_parse_combined(parser_context_t *ctx, const uint8_t *data,
9999
MEMZERO(request_hash, sizeof(request_hash));
100100
PARSER_ASSERT_OR_ERROR(zxerr_ok == crypto_getDigest(request_hash, call), parser_unexpected_error)
101101

102-
#if defined(TARGET_NANOS) || defined(TARGET_NANOX)
102+
#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2)
103103
MEMZERO(G_io_apdu_buffer, IO_APDU_BUFFER_SIZE);
104104
PARSER_ASSERT_OR_ERROR(memcmp(request_hash, request_id_stateread, 32) == 0, parser_context_invalid_chars)
105105
MEMCPY(G_io_apdu_buffer, request_hash, 32);

app/src/parser_impl.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ const char *parser_getErrorDescription(parser_error_t err) {
167167
CHECK_CBOR_MAP_ERR(_cbor_value_copy_string(&it, (V_OUTPUT).data, &(V_OUTPUT).len, NULL)); \
168168
}
169169

170+
#define READ_STRING_PTR_SIZE(MAP, FIELDNAME, V_OUTPUT_PTR, V_OUTPUT_SIZE) { \
171+
CborValue it; \
172+
CHECK_CBOR_MAP_ERR(cbor_value_map_find_value(MAP, FIELDNAME, &it)); \
173+
PARSER_ASSERT_OR_ERROR(cbor_value_is_byte_string(&it) || cbor_value_is_text_string(&it), parser_context_mismatch); \
174+
CHECK_CBOR_MAP_ERR(get_string_chunk(&it, (const void **)&V_OUTPUT_PTR, &V_OUTPUT_SIZE));\
175+
}
176+
170177
parser_error_t try_read_nonce(CborValue *content_map, parser_tx_t *v) {
171178
size_t stringLen = 0;
172179
CborValue it;
@@ -376,6 +383,19 @@ parser_error_t readPayload(parser_tx_t *v, uint8_t *buffer, size_t bufferLen) {
376383
return parser_unexpected_type;
377384
}
378385

386+
static bool isCandidTransaction(parser_tx_t *v) {
387+
char *method = v->tx_fields.call.method_name.data;
388+
if (strcmp(method, "manage_neuron") == 0) {
389+
return true;
390+
}
391+
392+
if (strcmp(method, "update_node_provider") == 0) {
393+
return true;
394+
}
395+
396+
return false;
397+
}
398+
379399
parser_error_t readContent(CborValue *content_map, parser_tx_t *v) {
380400
CborValue content_it;
381401
zemu_log_stack("read content");
@@ -410,8 +430,16 @@ parser_error_t readContent(CborValue *content_map, parser_tx_t *v) {
410430
READ_STRING(content_map, "method_name", fields->method_name)
411431
READ_INT64(content_map, "ingress_expiry", fields->ingress_expiry)
412432

413-
READ_STRING(content_map, "arg", fields->method_args)
414-
CHECK_PARSER_ERR(readPayload(v, fields->method_args.data, fields->method_args.len))
433+
if (isCandidTransaction(v)) {
434+
READ_STRING_PTR_SIZE(content_map, "arg", fields->method_args.dataPtr, fields->method_args.len)
435+
if (fields->method_args.dataPtr == NULL) {
436+
return parser_no_data;
437+
}
438+
CHECK_PARSER_ERR(readPayload(v, fields->method_args.dataPtr, fields->method_args.len))
439+
} else {
440+
READ_STRING(content_map, "arg", fields->method_args)
441+
CHECK_PARSER_ERR(readPayload(v, fields->method_args.data, fields->method_args.len))
442+
}
415443

416444
} else if (strcmp(v->request_type.data, "read_state") == 0) {
417445
state_read_t *fields = &v->tx_fields.stateRead;

app/src/parser_txdef.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,7 @@ extern "C" {
3838
#define METHOD_MAX_LEN 20
3939
#define NONCE_MAX_LEN 32
4040

41-
// For NanoS restrict max arg size
42-
#if defined(TARGET_NANOS)
43-
#define ARG_MAX_LEN 1000
44-
#else
45-
#define ARG_MAX_LEN 2000
46-
#endif
41+
#define ARG_MAX_LEN 1000
4742

4843
#define PATH_MAX_LEN 40
4944
#define PATH_MAX_ARRAY 2
@@ -124,6 +119,7 @@ typedef struct {
124119

125120
typedef struct {
126121
uint8_t data[ARG_MAX_LEN + 1];
122+
uint8_t *dataPtr;
127123
size_t len;
128124
} method_arg_t;
129125

6 Bytes
Loading
6 Bytes
Loading
445 Bytes
Loading
471 Bytes
Loading

0 commit comments

Comments
 (0)