From 668dfc40c70e754f2f56a165a750e40b0215e7aa Mon Sep 17 00:00:00 2001 From: Jack May Date: Tue, 17 Mar 2020 12:34:14 -0700 Subject: [PATCH] Align C and Rust handling of AccountInfos (#8906) --- .../bpf/c/src/error_handling/error_handling.c | 2 +- sdk/bpf/c/inc/solana_sdk.h | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/programs/bpf/c/src/error_handling/error_handling.c b/programs/bpf/c/src/error_handling/error_handling.c index cd611bed6a..36e0740c20 100644 --- a/programs/bpf/c/src/error_handling/error_handling.c +++ b/programs/bpf/c/src/error_handling/error_handling.c @@ -9,7 +9,7 @@ */ extern uint64_t entrypoint(const uint8_t *input) { - SolKeyedAccount ka[4]; + SolKeyedAccount ka[1]; SolParameters params = (SolParameters) { .ka = ka }; if (!sol_deserialize(input, ¶ms, SOL_ARRAY_SIZE(ka))) { diff --git a/sdk/bpf/c/inc/solana_sdk.h b/sdk/bpf/c/inc/solana_sdk.h index 340d58fbc5..b188e14daa 100644 --- a/sdk/bpf/c/inc/solana_sdk.h +++ b/sdk/bpf/c/inc/solana_sdk.h @@ -284,13 +284,29 @@ SOL_FN_PREFIX bool sol_deserialize( } params->ka_num = *(uint64_t *) input; input += sizeof(uint64_t); - if (ka_num < params->ka_num) { + + if (ka_num > params->ka_num) { return false; } for (int i = 0; i < params->ka_num; i++) { uint8_t dup_info = input[0]; input += sizeof(uint8_t); + + if (i >= ka_num) { + if (dup_info == UINT8_MAX) { + input += sizeof(uint8_t); + input += sizeof(uint8_t); + input += sizeof(SolPubkey); + input += sizeof(uint64_t); + input += *(uint64_t *) input; + input += sizeof(uint64_t); + input += sizeof(SolPubkey); + input += sizeof(uint8_t); + input += sizeof(uint64_t); + } + continue; + } if (dup_info == UINT8_MAX) { // is signer? params->ka[i].is_signer = *(uint8_t *) input != 0; @@ -418,7 +434,6 @@ SOL_FN_PREFIX void sol_log_params(const SolParameters *params) { */ uint64_t entrypoint(const uint8_t *input); - #ifdef SOL_TEST /** * Stub log functions when building tests