Skip to content

Commit

Permalink
add elf_sz field
Browse files Browse the repository at this point in the history
  • Loading branch information
ravyu-jump committed Jun 4, 2024
1 parent 72e20af commit d68634a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
21 changes: 19 additions & 2 deletions src/flamenco/runtime/tests/fd_exec_instr_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -899,8 +899,25 @@ fd_sbpf_program_load_test_run( fd_exec_test_elf_loader_ctx_t const * input,
return 0UL;
}

ulong elf_sz = input->elf.data->size;
void const * _bin = input->elf.data->bytes;
ulong elf_sz = input->elf_sz;
void const * _bin;

/* elf_sz will be passed as arguments to elf loader functions.
pb decoder allocates memory for elf.data based on its actual size,
not elf_sz (the decoupling is intentional to test underflow/overflow behavior).
If elf_sz is larger than the size of actual elf data, this may result
in out-of-bounds accesses which will upset ASAN (however intentional).
So in this case we just copy the data into a memory region of elf_sz bytes */
if ( elf_sz > input->elf.data->size ){
void * tmp = fd_valloc_malloc( valloc, 1UL, elf_sz );
if ( FD_UNLIKELY( !tmp ) ){
return 0UL;
}
fd_memcpy( tmp, input->elf.data->bytes, input->elf.data->size );
_bin = tmp;
} else {
_bin = input->elf.data->bytes;
}

// Allocate space for captured effects
ulong output_end = (ulong)output_buf + output_bufsz;
Expand Down
12 changes: 9 additions & 3 deletions src/flamenco/runtime/tests/fd_exec_test.pb.h

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

1 change: 1 addition & 0 deletions src/flamenco/runtime/tests/fd_exec_test.proto
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ message ELFBinary {
message ELFLoaderCtx {
ELFBinary elf = 1;
FeatureSet features = 2;
uint64 elf_sz = 3;
}

// Captures the results of a elf binary load.
Expand Down

0 comments on commit d68634a

Please sign in to comment.