From 9a4e1095cad154b7f8ce41cedbfb1e9a7e137d66 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 16 Nov 2021 22:55:54 +0100 Subject: [PATCH] linux-dmabuf-v1: properly validate flags We were send a protocol error if INTERLACED or BOTTOM_FIRST was set. This is incorrect for the zwp_linux_dmabuf_params.create code-path because this kills the client without allowing it to gracefully handle the error. We should only send a protocol error if the client provides a bit not listed in the protocol definition. --- types/wlr_linux_dmabuf_v1.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/types/wlr_linux_dmabuf_v1.c b/types/wlr_linux_dmabuf_v1.c index 7b08b350..b111a721 100644 --- a/types/wlr_linux_dmabuf_v1.c +++ b/types/wlr_linux_dmabuf_v1.c @@ -204,6 +204,17 @@ static void params_create_common(struct wl_resource *params_resource, goto err_out; } + /* reject unknown flags */ + uint32_t all_flags = ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT | + ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_INTERLACED | + ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_BOTTOM_FIRST; + if (flags & ~all_flags) { + wl_resource_post_error(params_resource, + ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT, + "Unknown dmabuf flags %"PRIu32, flags); + goto err_out; + } + attribs.width = width; attribs.height = height; attribs.format = format; @@ -265,14 +276,6 @@ static void params_create_common(struct wl_resource *params_resource, } } - /* reject unknown flags */ - if (attribs.flags & ~ZWP_LINUX_BUFFER_PARAMS_V1_FLAGS_Y_INVERT) { - wl_resource_post_error(params_resource, - ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT, - "Unknown dmabuf flags %"PRIu32, attribs.flags); - goto err_out; - } - /* Check if dmabuf is usable */ if (!check_import_dmabuf(linux_dmabuf, &attribs)) { goto err_failed;