Skip to content

Commit

Permalink
Don't crash on out of memory (#335)
Browse files Browse the repository at this point in the history
Found by fault injection

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
  • Loading branch information
dthaler committed Aug 15, 2023
1 parent f5eb301 commit 89b84c6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions vm/ubpf_jit_arm64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,11 @@ ubpf_translate_arm64(struct ubpf_vm* vm, uint8_t* buffer, size_t* size, char** e
state.jumps = calloc(UBPF_MAX_INSTS, sizeof(state.jumps[0]));
state.num_jumps = 0;

if (!state.pc_locs || !state.jumps) {
*errmsg = ubpf_error("Out of memory");
goto out;
}

if (translate(vm, &state, errmsg) < 0) {
goto out;
}
Expand Down
5 changes: 5 additions & 0 deletions vm/ubpf_jit_x86_64.c
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,11 @@ ubpf_translate_x86_64(struct ubpf_vm* vm, uint8_t* buffer, size_t* size, char**
state.jumps = calloc(UBPF_MAX_INSTS, sizeof(state.jumps[0]));
state.num_jumps = 0;

if (!state.pc_locs || !state.jumps) {
*errmsg = ubpf_error("Out of memory");
goto out;
}

if (translate(vm, &state, errmsg) < 0) {
goto out;
}
Expand Down

0 comments on commit 89b84c6

Please sign in to comment.