Skip to content

Commit

Permalink
providers/virtualbox: explicitly check for allocation failures
Browse files Browse the repository at this point in the history
The failure to do so should be harmless (we'll fail either way) but it's
best to be explicit.
  • Loading branch information
bgilbert committed Jun 7, 2022
1 parent ebdb25a commit f90c0dd
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 f90c0dd

Please sign in to comment.