Skip to content

Add assertion to prevent buffer overflow #376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ static inline void emit_load_imm(struct jit_state *state, int dst, int64_t imm);
static inline void offset_map_insert(struct jit_state *state, int32_t target_pc)
{
struct offset_map *map_entry = &state->offset_map[state->n_insn++];
assert(state->n_insn < MAX_INSNS);
map_entry->pc = target_pc;
map_entry->offset = state->offset;
}
Expand Down Expand Up @@ -352,6 +353,7 @@ static inline void emit_jump_target_address(struct jit_state *state,
int32_t target_pc)
{
struct jump *jump = &state->jumps[state->n_jumps++];
assert(state->n_jumps < MAX_INSNS);
jump->offset_loc = state->offset;
jump->target_pc = target_pc;
emit4(state, 0);
Expand Down Expand Up @@ -553,6 +555,7 @@ static inline void emit_jump_target_offset(struct jit_state *state,
uint32_t jump_state_offset)
{
struct jump *jump = &state->jumps[state->n_jumps++];
assert(state->n_jumps < MAX_INSNS);
jump->offset_loc = jump_loc;
jump->target_offset = jump_state_offset;
}
Expand Down Expand Up @@ -930,6 +933,7 @@ static inline void emit_jmp(struct jit_state *state, uint32_t target_pc)
emit_jump_target_address(state, target_pc);
#elif defined(__aarch64__)
struct jump *jump = &state->jumps[state->n_jumps++];
assert(state->n_jumps < MAX_INSNS);
jump->offset_loc = state->offset;
jump->target_pc = target_pc;
emit_a64(state, UBR_B);
Expand Down