Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2012 Intel Corporation |
| 3 | * Copyright © 2013 Collabora, Ltd. |
| 4 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 5 | * Permission is hereby granted, free of charge, to any person obtaining |
| 6 | * a copy of this software and associated documentation files (the |
| 7 | * "Software"), to deal in the Software without restriction, including |
| 8 | * without limitation the rights to use, copy, modify, merge, publish, |
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 10 | * permit persons to whom the Software is furnished to do so, subject to |
| 11 | * the following conditions: |
Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 12 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial |
| 15 | * portions of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 21 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 22 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 23 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 24 | * SOFTWARE. |
Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 25 | */ |
| 26 | |
Andrew Wedgbury | 9cd661e | 2014-04-07 12:40:35 +0100 | [diff] [blame] | 27 | #include "config.h" |
| 28 | |
Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 29 | #include <unistd.h> |
Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 30 | |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 31 | #include "shared/os-compatibility.h" |
Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 32 | #include "weston-test-client-helper.h" |
| 33 | |
| 34 | /* tests, that attempt to crash the compositor on purpose */ |
| 35 | |
| 36 | static struct wl_buffer * |
| 37 | create_bad_shm_buffer(struct client *client, int width, int height) |
| 38 | { |
| 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; |
| 44 | int fd; |
| 45 | |
| 46 | fd = os_create_anonymous_file(size); |
| 47 | assert(fd >= 0); |
| 48 | |
| 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); |
| 53 | |
| 54 | /* Truncate the file to a small size, so that the compositor |
| 55 | * will access it out-of-bounds, and hit SIGBUS. |
| 56 | */ |
| 57 | assert(ftruncate(fd, 12) == 0); |
| 58 | close(fd); |
| 59 | |
| 60 | return buffer; |
| 61 | } |
| 62 | |
Marek Chalupa | cfff312 | 2014-07-16 11:40:25 +0200 | [diff] [blame] | 63 | TEST(test_truncated_shm_file) |
Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 64 | { |
| 65 | struct client *client; |
| 66 | struct wl_buffer *bad_buffer; |
| 67 | struct wl_surface *surface; |
| 68 | int frame; |
| 69 | |
Pekka Paalanen | 4ac06ff | 2015-03-26 12:56:10 +0200 | [diff] [blame] | 70 | client = create_client_and_test_surface(46, 76, 111, 134); |
Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 71 | assert(client); |
| 72 | surface = client->surface->wl_surface; |
| 73 | |
| 74 | bad_buffer = create_bad_shm_buffer(client, 200, 200); |
| 75 | |
Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 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); |
Marek Chalupa | cfff312 | 2014-07-16 11:40:25 +0200 | [diff] [blame] | 80 | frame_callback_wait_nofail(client, &frame); |
| 81 | |
| 82 | expect_protocol_error(client, &wl_buffer_interface, |
| 83 | WL_SHM_ERROR_INVALID_FD); |
Pekka Paalanen | f812477 | 2013-11-21 16:47:02 +0200 | [diff] [blame] | 84 | } |