ENOMEM checks: consistently check wl_array_add return

This commit is contained in:
Dominique Martinet 2017-12-28 09:44:35 +01:00
parent 9c163b7d38
commit 3eb4fa15ee
5 changed files with 40 additions and 4 deletions

View file

@ -907,6 +907,9 @@ static void data_source_offer(struct wl_client *client,
*p = strdup(mime_type); *p = strdup(mime_type);
} }
if (!p || !*p){ if (!p || !*p){
if (p) {
source->mime_types.size -= sizeof *p;
}
wl_resource_post_no_memory(resource); wl_resource_post_no_memory(resource);
} }
} }

View file

@ -127,6 +127,9 @@ static void source_handle_offer(struct wl_client *client,
*p = strdup(mime_type); *p = strdup(mime_type);
} }
if (p == NULL || *p == NULL) { if (p == NULL || *p == NULL) {
if (p) {
source->mime_types.size -= sizeof(*p);
}
wl_resource_post_no_memory(resource); wl_resource_post_no_memory(resource);
} }
} }

View file

@ -876,6 +876,11 @@ void wlr_seat_keyboard_enter(struct wlr_seat *seat,
wl_array_init(&keys); wl_array_init(&keys);
for (size_t i = 0; i < keyboard->num_keycodes; ++i) { for (size_t i = 0; i < keyboard->num_keycodes; ++i) {
uint32_t *p = wl_array_add(&keys, sizeof(uint32_t)); 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]; *p = keyboard->keycodes[i];
} }
uint32_t serial = wl_display_next_serial(seat->display); uint32_t serial = wl_display_next_serial(seat->display);

View file

@ -922,19 +922,35 @@ static void wlr_xdg_toplevel_v6_send_configure(
wl_array_init(&states); wl_array_init(&states);
if (surface->toplevel_state->pending.maximized) { if (surface->toplevel_state->pending.maximized) {
s = wl_array_add(&states, sizeof(uint32_t)); s = wl_array_add(&states, sizeof(uint32_t));
*s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED; if (!s) {
wlr_log(L_ERROR, "Could not allocate state for maximized xdg_toplevel");
} else {
*s = ZXDG_TOPLEVEL_V6_STATE_MAXIMIZED;
}
} }
if (surface->toplevel_state->pending.fullscreen) { if (surface->toplevel_state->pending.fullscreen) {
s = wl_array_add(&states, sizeof(uint32_t)); s = wl_array_add(&states, sizeof(uint32_t));
*s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN; if (!s) {
wlr_log(L_ERROR, "Could not allocate state for fullscreen xdg_toplevel");
} else {
*s = ZXDG_TOPLEVEL_V6_STATE_FULLSCREEN;
}
} }
if (surface->toplevel_state->pending.resizing) { if (surface->toplevel_state->pending.resizing) {
s = wl_array_add(&states, sizeof(uint32_t)); s = wl_array_add(&states, sizeof(uint32_t));
*s = ZXDG_TOPLEVEL_V6_STATE_RESIZING; if (!s) {
wlr_log(L_ERROR, "Could not allocate state for resizing xdg_toplevel");
} else {
*s = ZXDG_TOPLEVEL_V6_STATE_RESIZING;
}
} }
if (surface->toplevel_state->pending.activated) { if (surface->toplevel_state->pending.activated) {
s = wl_array_add(&states, sizeof(uint32_t)); s = wl_array_add(&states, sizeof(uint32_t));
*s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED; if (!s) {
wlr_log(L_ERROR, "Could not allocate state for activated xdg_toplevel");
} else {
*s = ZXDG_TOPLEVEL_V6_STATE_ACTIVATED;
}
} }
uint32_t width = surface->toplevel_state->pending.width; uint32_t width = surface->toplevel_state->pending.width;

View file

@ -55,6 +55,15 @@ static int xwm_read_data_source(int fd, uint32_t mask, void *data) {
int current = selection->source_data.size; int current = selection->source_data.size;
if (selection->source_data.size < incr_chunk_size) { if (selection->source_data.size < incr_chunk_size) {
p = wl_array_add(&selection->source_data, 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 to read into, throwing away some input");
/* if we just return now, we'll just be called
* again right away - force read something.
* 1K on stack is probably fine? */
char junk[1024];
read(fd, junk, sizeof(junk));
return 1;
}
} else { } else {
p = (char *) selection->source_data.data + selection->source_data.size; p = (char *) selection->source_data.data + selection->source_data.size;
} }