From eefeec12fdf725cc78ca425f98a0cae9f622a14b Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 30 Oct 2019 15:31:54 +0100 Subject: [PATCH] oxr: check input type in oxr_swapchain_gl_enumerate_images Don't blindly cast the input struct to XrSwapchainImageOpenGLKHR, check that the type is XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR. --- src/xrt/state_trackers/oxr/oxr_swapchain_gl.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/xrt/state_trackers/oxr/oxr_swapchain_gl.c b/src/xrt/state_trackers/oxr/oxr_swapchain_gl.c index d67009a07..df353f7b8 100644 --- a/src/xrt/state_trackers/oxr/oxr_swapchain_gl.c +++ b/src/xrt/state_trackers/oxr/oxr_swapchain_gl.c @@ -8,6 +8,7 @@ * @ingroup comp_client */ +#include #include #include "xrt/xrt_gfx_xlib.h" @@ -39,10 +40,20 @@ oxr_swapchain_gl_enumerate_images(struct oxr_logger *log, XrSwapchainImageBaseHeader *images) { struct xrt_swapchain_gl *xsc = (struct xrt_swapchain_gl *)sc->swapchain; + + assert(count > 0); + if (images[0].type != XR_TYPE_SWAPCHAIN_IMAGE_OPENGL_KHR) { + return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, + "unsupported XrSwapchainImageBaseHeader type"); + } XrSwapchainImageOpenGLKHR *gl_imgs = (XrSwapchainImageOpenGLKHR *)images; for (uint32_t i = 0; i < count; i++) { + if (gl_imgs[i].type != images[0].type) { + return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, + "images array contains mixed types"); + } gl_imgs[i].image = xsc->images[i]; } -- GitLab