2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2013 Collabora, Ltd.
5 * Permission to use, copy, modify, distribute, and sell this software and
6 * its documentation for any purpose is hereby granted without fee, provided
7 * that the above copyright notice appear in all copies and that both that
8 * copyright notice and this permission notice appear in supporting
9 * documentation, and that the name of the copyright holders not be used in
10 * advertising or publicity pertaining to distribution of the software
11 * without specific, written prior permission. The copyright holders make
12 * no representations about the suitability of this software for any
13 * purpose. It is provided "as is" without express or implied warranty.
15 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
20 * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27 #include <sys/types.h>
31 #include "../shared/os-compatibility.h"
32 #include "weston-test-client-helper.h"
34 /* tests, that attempt to crash the compositor on purpose */
36 static struct wl_buffer *
37 create_bad_shm_buffer(struct client *client, int width, int height)
39 struct wl_shm *shm = client->wl_shm;
40 int stride = width * 4;
41 int size = stride * height;
42 struct wl_shm_pool *pool;
43 struct wl_buffer *buffer;
46 fd = os_create_anonymous_file(size);
49 pool = wl_shm_create_pool(shm, fd, size);
50 buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride,
51 WL_SHM_FORMAT_ARGB8888);
52 wl_shm_pool_destroy(pool);
54 /* Truncate the file to a small size, so that the compositor
55 * will access it out-of-bounds, and hit SIGBUS.
57 assert(ftruncate(fd, 12) == 0);
63 TEST(test_truncated_shm_file)
65 struct client *client;
66 struct wl_buffer *bad_buffer;
67 struct wl_surface *surface;
70 client = client_create(46, 76, 111, 134);
72 surface = client->surface->wl_surface;
74 bad_buffer = create_bad_shm_buffer(client, 200, 200);
76 wl_surface_attach(surface, bad_buffer, 0, 0);
77 wl_surface_damage(surface, 0, 0, 200, 200);
78 frame_callback_set(surface, &frame);
79 wl_surface_commit(surface);
80 frame_callback_wait_nofail(client, &frame);
82 expect_protocol_error(client, &wl_buffer_interface,
83 WL_SHM_ERROR_INVALID_FD);