Skip to content

Commit

Permalink
Merge pull request #1394 from bgilbert/malloc
Browse files Browse the repository at this point in the history
providers/virtualbox: explicitly check for allocation failures
  • Loading branch information
bgilbert committed Jun 7, 2022
2 parents ebdb25a + f90c0dd commit 03eafa4
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/providers/virtualbox/virtualbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ static int get_prop(int fd, uint32_t client_id, const char *name, void **value,
// init header
size_t msg_size = sizeof(struct vbg_ioctl_hgcm_call) + 4 * sizeof(struct vmmdev_hgcm_function_parameter64);
struct vbg_ioctl_hgcm_call _cleanup_free_ *msg = calloc(1, msg_size);
if (msg == NULL) {
return VERR_NO_MEMORY;
}
// init_header re-adds the size of msg->hdr
init_header(&msg->hdr, msg_size - sizeof(msg->hdr), msg_size - sizeof(msg->hdr));
msg->client_id = client_id;
Expand Down Expand Up @@ -131,6 +134,9 @@ static int get_prop(int fd, uint32_t client_id, const char *name, void **value,
; // labels can't point to declarations
size_t buf_size = params[3].u.value32;
void _cleanup_free_ *buf = malloc(buf_size);
if (buf == NULL) {
return VERR_NO_MEMORY;
}
params[1].u.pointer.size = buf_size;
params[1].u.pointer.u.linear_addr = (uintptr_t) buf;

Expand Down Expand Up @@ -161,6 +167,9 @@ static int del_prop(int fd, uint32_t client_id, const char *name) {
// init header
size_t msg_size = sizeof(struct vbg_ioctl_hgcm_call) + sizeof(struct vmmdev_hgcm_function_parameter64);
struct vbg_ioctl_hgcm_call _cleanup_free_ *msg = calloc(1, msg_size);
if (msg == NULL) {
return VERR_NO_MEMORY;
}
// init_header re-adds the size of msg->hdr
init_header(&msg->hdr, msg_size - sizeof(msg->hdr), msg_size - sizeof(msg->hdr));
msg->client_id = client_id;
Expand Down

0 comments on commit 03eafa4

Please sign in to comment.