Skip to content

Commit

Permalink
Non-conflicting account duplicate marker value (#8206)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackcmay authored Feb 11, 2020
1 parent 890919d commit 517fe73
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
11 changes: 4 additions & 7 deletions programs/bpf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub fn serialize_parameters(
if is_dup {
v.write_u8(position as u8).unwrap();
} else {
v.write_u8(0).unwrap();
v.write_u8(std::u8::MAX).unwrap();
v.write_u8(keyed_account.signer_key().is_some() as u8)
.unwrap();
v.write_u8(keyed_account.is_writable() as u8).unwrap();
Expand Down Expand Up @@ -375,6 +375,7 @@ mod tests {
// Case: With duplicate accounts
let duplicate_key = Pubkey::new_rand();
let parameter_account = Account::new_ref(1, 0, &program_id);
let mut keyed_accounts = vec![KeyedAccount::new(&program_key, false, &program_account)];
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, &parameter_account));
keyed_accounts.push(KeyedAccount::new(&duplicate_key, false, &parameter_account));
assert_eq!(
Expand Down
Binary file modified programs/bpf_loader/test_elfs/noop.so
Binary file not shown.
26 changes: 25 additions & 1 deletion sdk/bpf/c/inc/solana_sdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ static_assert(sizeof(int64_t) == 8);
static_assert(sizeof(uint64_t) == 8);
#endif

/**
* Minimum of signed integral types
*/
# define INT8_MIN (-128)
# define INT16_MIN (-32767-1)
# define INT32_MIN (-2147483647-1)
# define INT64_MIN (-__INT64_C(9223372036854775807)-1)

/**
* Maximum of signed integral types
*/
# define INT8_MAX (127)
# define INT16_MAX (32767)
# define INT32_MAX (2147483647)
# define INT64_MAX (__INT64_C(9223372036854775807))

/**
* Maximum of unsigned integral types
*/
# define UINT8_MAX (255)
# define UINT16_MAX (65535)
# define UINT32_MAX (4294967295U)
# define UINT64_MAX (__UINT64_C(18446744073709551615))

/**
* NULL
*/
Expand Down Expand Up @@ -265,7 +289,7 @@ SOL_FN_PREFIX bool sol_deserialize(
for (int i = 0; i < params->ka_num; i++) {
uint8_t dup_info = input[0];
input += sizeof(uint8_t);
if (dup_info == 0) {
if (dup_info == UINT8_MAX) {
// is signer?
params->ka[i].is_signer = *(uint8_t *) input != 0;
input += sizeof(uint8_t);
Expand Down
6 changes: 3 additions & 3 deletions sdk/src/entrypoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a

let mut accounts = Vec::with_capacity(num_accounts);
for _ in 0..num_accounts {
let dup_info = *(input.add(offset) as *const u8) as usize;
let dup_info = *(input.add(offset) as *const u8);
offset += size_of::<u8>();
if dup_info == 0 {
if dup_info == std::u8::MAX {
let is_signer = {
#[allow(clippy::cast_ptr_alignment)]
let is_signer = *(input.add(offset) as *const u8);
Expand Down Expand Up @@ -110,7 +110,7 @@ pub unsafe fn deserialize<'a>(input: *mut u8) -> (&'a Pubkey, Vec<AccountInfo<'a
});
} else {
// Duplicate account, clone the original
accounts.push(accounts[dup_info].clone());
accounts.push(accounts[dup_info as usize].clone());
}
}

Expand Down

0 comments on commit 517fe73

Please sign in to comment.