aboutsummaryrefslogtreecommitdiffstats
path: root/src/connection.c
diff options
context:
space:
mode:
authorPekka Paalanen <pekka.paalanen@collabora.com>2019-03-06 13:42:23 +0200
committerPekka Paalanen <pekka.paalanen@collabora.com>2019-03-13 12:39:16 +0200
commitbace3cd819798571189671b68590adff3fd40997 (patch)
tree039cfca495d742b269649c7fc13e03a7ed6f87e9 /src/connection.c
parenttests: add request_bogus_size (diff)
downloadwayland-bace3cd819798571189671b68590adff3fd40997.tar
wayland-bace3cd819798571189671b68590adff3fd40997.tar.gz
wayland-bace3cd819798571189671b68590adff3fd40997.tar.bz2
wayland-bace3cd819798571189671b68590adff3fd40997.tar.lz
wayland-bace3cd819798571189671b68590adff3fd40997.tar.xz
wayland-bace3cd819798571189671b68590adff3fd40997.tar.zst
wayland-bace3cd819798571189671b68590adff3fd40997.zip
connection: fix demarshal of invalid header
The size argument to wl_connection_demarshal() is taken from the message by the caller wl_client_connection_data(), therefore 'size' is untrusted data controllable by a Wayland client. The size should always be at least the header size, otherwise the header is invalid. If the size is smaller than header size, it leads to reading past the end of allocated memory. Furthermore if size is zero, wl_closure_init() changes behaviour and leaves num_arrays uninitialized, leading to access of arbitrary memory. Check that 'size' fits at least the header. The space for arguments is already properly checked. This makes the request_bogus_size test free of errors under Valgrind. Fixes: https://gitlab.freedesktop.org/wayland/wayland/issues/52 Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com> Reviewed-by: Simon Ser <contact@emersion.fr>
Diffstat (limited to 'src/connection.c')
-rw-r--r--src/connection.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/connection.c b/src/connection.c
index 474c97b..7fba999 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -695,6 +695,14 @@ wl_connection_demarshal(struct wl_connection *connection,
struct wl_closure *closure;
struct wl_array *array_extra;
+ /* Space for sender_id and opcode */
+ if (size < 2 * sizeof *p) {
+ wl_log("message too short, invalid header\n");
+ wl_connection_consume(connection, size);
+ errno = EINVAL;
+ return NULL;
+ }
+
closure = wl_closure_init(message, size, &num_arrays, NULL);
if (closure == NULL) {
wl_connection_consume(connection, size);