aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2017-12-28 07:44:21 -0800
committerGitHub <noreply@github.com>2017-12-28 07:44:21 -0800
commitbb24895a2b1759ec78ae68bb91d13a98dc3cc9c7 (patch)
tree8c76d2152a6b21f98c879a2b5ecf4dfb05d3ff9c
parent04b7701e1b7a7f371caffecafae07467aa8970e7 (diff)
parentb0e440b5b1e1de0030947c68cdc34b0fd902c5e8 (diff)
Merge pull request #533 from martinetd/wl_array_add
ENOMEM checks: consistently check wl_array_add return
-rw-r--r--backend/drm/util.c2
-rw-r--r--examples/screenshot.c2
-rw-r--r--types/wlr_data_device.c5
-rw-r--r--types/wlr_primary_selection.c3
-rw-r--r--types/wlr_seat.c5
-rw-r--r--types/wlr_xdg_shell_v6.c21
-rw-r--r--xwayland/selection.c18
7 files changed, 48 insertions, 8 deletions
diff --git a/backend/drm/util.c b/backend/drm/util.c
index 25256343..37d99aa8 100644
--- a/backend/drm/util.c
+++ b/backend/drm/util.c
@@ -223,7 +223,7 @@ static bool match_obj_(struct match_state *st, size_t skips, size_t score, size_
if (score > st->score || (score == st->score && replaced < st->replaced)) {
st->score = score;
st->replaced = replaced;
- memcpy(st->best, st->res, sizeof st->best[0] * st->num_res);
+ memcpy(st->best, st->res, sizeof(st->best[0]) * st->num_res);
if (st->score == st->num_objs && st->replaced == 0) {
st->exit_early = true;
diff --git a/examples/screenshot.c b/examples/screenshot.c
index 932f5e37..77652805 100644
--- a/examples/screenshot.c
+++ b/examples/screenshot.c
@@ -95,7 +95,7 @@ static void handle_global(void *data, struct wl_registry *registry,
static struct screenshooter_output *output;
if (strcmp(interface, "wl_output") == 0) {
- output = calloc(1, sizeof *output);
+ output = calloc(1, sizeof(*output));
output->output = wl_registry_bind(registry, name, &wl_output_interface,
1);
wl_list_insert(&output_list, &output->link);
diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c
index af81d861..a9f54a0b 100644
--- a/types/wlr_data_device.c
+++ b/types/wlr_data_device.c
@@ -901,12 +901,15 @@ static void data_source_offer(struct wl_client *client,
wl_resource_get_user_data(resource);
char **p;
- p = wl_array_add(&source->mime_types, sizeof *p);
+ p = wl_array_add(&source->mime_types, sizeof(*p));
if (p) {
*p = strdup(mime_type);
}
if (!p || !*p){
+ if (p) {
+ source->mime_types.size -= sizeof(*p);
+ }
wl_resource_post_no_memory(resource);
}
}
diff --git a/types/wlr_primary_selection.c b/types/wlr_primary_selection.c
index 8163d2e5..1228e94e 100644
--- a/types/wlr_primary_selection.c
+++ b/types/wlr_primary_selection.c
@@ -127,6 +127,9 @@ static void source_handle_offer(struct wl_client *client,
*p = strdup(mime_type);
}
if (p == NULL || *p == NULL) {
+ if (p) {
+ source->mime_types.size -= sizeof(*p);
+ }
wl_resource_post_no_memory(resource);
}
}
diff --git a/types/wlr_seat.c b/types/wlr_seat.c
index 156ac142..2a79f784 100644
--- a/types/wlr_seat.c
+++ b/types/wlr_seat.c
@@ -876,6 +876,11 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat,
wl_array_init(&keys);
for (size_t i = 0; i < keyboard->num_keycodes; ++i) {
uint32_t *p = wl_array_add(&keys, sizeof(uint32_t));
+ if (!p) {
+ wlr_log(L_ERROR, "Cannot allocate memory, skipping keycode: %d\n",
+ keyboard->keycodes[i]);
+ continue;
+ }
*p = keyboard->keycodes[i];
}
uint32_t serial = wl_display_next_serial(seat->display);
diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c
index ead5a73e..1c46197e 100644
--- a/types/wlr_xdg_shell_v6.c
+++ b/types/wlr_xdg_shell_v6.c
@@ -922,18 +922,34 @@ static void wlr_xdg_toplevel_v6_send_configure(
wl_array_init(&states);
if (surface->toplevel_state->pending.maximized) {
s = wl_array_add(&states, sizeof(uint32_t));
+ if (!s) {
+ wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel");
+ goto error_out;
+ }
*s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED;
}
if (surface->toplevel_state->pending.fullscreen) {
s = wl_array_add(&states, sizeof(uint32_t));
+ if (!s) {
+ wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel");
+ goto error_out;
+ }
*s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN;
}
if (surface->toplevel_state->pending.resizing) {
s = wl_array_add(&states, sizeof(uint32_t));
+ if (!s) {
+ wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel");
+ goto error_out;
+ }
*s = ZXDG_TOPLEVEL_V6_STATE_RESIZING;
}
if (surface->toplevel_state->pending.activated) {
s = wl_array_add(&states, sizeof(uint32_t));
+ if (!s) {
+ wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel");
+ goto error_out;
+ }
*s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED;
}
@@ -949,6 +965,11 @@ static void wlr_xdg_toplevel_v6_send_configure(
height, &states);
wl_array_release(&states);
+ return;
+
+error_out:
+ wl_array_release(&states);
+ wl_resource_post_no_memory(surface->toplevel_state->resource);
}
static void wlr_xdg_surface_send_configure(void *user_data) {
diff --git a/xwayland/selection.c b/xwayland/selection.c
index 0d7f1588..00e45182 100644
--- a/xwayland/selection.c
+++ b/xwayland/selection.c
@@ -55,6 +55,10 @@ static int xwm_read_data_source(int fd, uint32_t mask, void *data) {
int current = selection->source_data.size;
if (selection->source_data.size < incr_chunk_size) {
p = wl_array_add(&selection->source_data, incr_chunk_size);
+ if (!p){
+ wlr_log(L_ERROR, "Could not allocate selection source_data");
+ goto error_out;
+ }
} else {
p = (char *) selection->source_data.data + selection->source_data.size;
}
@@ -64,11 +68,7 @@ static int xwm_read_data_source(int fd, uint32_t mask, void *data) {
int len = read(fd, p, available);
if (len == -1) {
wlr_log(L_ERROR, "read error from data source: %m");
- xwm_selection_send_notify(selection, XCB_ATOM_NONE);
- wl_event_source_remove(selection->property_source);
- selection->property_source = NULL;
- close(fd);
- wl_array_release(&selection->source_data);
+ goto error_out;
}
wlr_log(L_DEBUG, "read %d (available %d, mask 0x%x) bytes: \"%.*s\"",
@@ -140,6 +140,14 @@ static int xwm_read_data_source(int fd, uint32_t mask, void *data) {
}
return 1;
+
+error_out:
+ xwm_selection_send_notify(selection, XCB_ATOM_NONE);
+ wl_event_source_remove(selection->property_source);
+ selection->property_source = NULL;
+ close(fd);
+ wl_array_release(&selection->source_data);
+ return 0;
}
static void xwm_selection_source_send(struct wlr_xwm_selection *selection,