blob: 517573127135c54fdaca7d70b23a90e5b1e10b89 [file] [log] [blame]
Pekka Paalanenf8124772013-11-21 16:47:02 +02001/*
2 * Copyright © 2012 Intel Corporation
3 * Copyright © 2013 Collabora, Ltd.
4 *
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.
14 *
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.
22 */
23
Andrew Wedgbury9cd661e2014-04-07 12:40:35 +010024#include "config.h"
25
Pekka Paalanenf8124772013-11-21 16:47:02 +020026#include <unistd.h>
Pekka Paalanenf8124772013-11-21 16:47:02 +020027
28#include "../shared/os-compatibility.h"
29#include "weston-test-client-helper.h"
30
31/* tests, that attempt to crash the compositor on purpose */
32
33static struct wl_buffer *
34create_bad_shm_buffer(struct client *client, int width, int height)
35{
36 struct wl_shm *shm = client->wl_shm;
37 int stride = width * 4;
38 int size = stride * height;
39 struct wl_shm_pool *pool;
40 struct wl_buffer *buffer;
41 int fd;
42
43 fd = os_create_anonymous_file(size);
44 assert(fd >= 0);
45
46 pool = wl_shm_create_pool(shm, fd, size);
47 buffer = wl_shm_pool_create_buffer(pool, 0, width, height, stride,
48 WL_SHM_FORMAT_ARGB8888);
49 wl_shm_pool_destroy(pool);
50
51 /* Truncate the file to a small size, so that the compositor
52 * will access it out-of-bounds, and hit SIGBUS.
53 */
54 assert(ftruncate(fd, 12) == 0);
55 close(fd);
56
57 return buffer;
58}
59
Marek Chalupacfff3122014-07-16 11:40:25 +020060TEST(test_truncated_shm_file)
Pekka Paalanenf8124772013-11-21 16:47:02 +020061{
62 struct client *client;
63 struct wl_buffer *bad_buffer;
64 struct wl_surface *surface;
65 int frame;
66
Pekka Paalanen4ac06ff2015-03-26 12:56:10 +020067 client = create_client_and_test_surface(46, 76, 111, 134);
Pekka Paalanenf8124772013-11-21 16:47:02 +020068 assert(client);
69 surface = client->surface->wl_surface;
70
71 bad_buffer = create_bad_shm_buffer(client, 200, 200);
72
Pekka Paalanenf8124772013-11-21 16:47:02 +020073 wl_surface_attach(surface, bad_buffer, 0, 0);
74 wl_surface_damage(surface, 0, 0, 200, 200);
75 frame_callback_set(surface, &frame);
76 wl_surface_commit(surface);
Marek Chalupacfff3122014-07-16 11:40:25 +020077 frame_callback_wait_nofail(client, &frame);
78
79 expect_protocol_error(client, &wl_buffer_interface,
80 WL_SHM_ERROR_INVALID_FD);
Pekka Paalanenf8124772013-11-21 16:47:02 +020081}