Commit bace3cd8 authored by Pekka Paalanen's avatar Pekka Paalanen

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: #52Signed-off-by: Pekka Paalanen's avatarPekka Paalanen <pekka.paalanen@collabora.com>
Reviewed-by: Simon Ser's avatarSimon Ser <contact@emersion.fr>
parent 446047ed
......@@ -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);
......
......@@ -798,7 +798,7 @@ expect_error_recv(int sockfd, uint32_t expected_error)
* However, running under Valgrind would point out invalid reads and use of
* uninitialized values.
*/
FAIL_TEST(request_bogus_size)
TEST(request_bogus_size)
{
struct wl_display *display;
struct wl_client *client;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment