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.
This commit is contained in:
Simon Ser 2019-10-30 15:31:54 +01:00 committed by Ryan Pavlik
parent 3b87d518c4
commit eefeec12fd

View file

@ -8,6 +8,7 @@
* @ingroup comp_client
*/
#include <assert.h>
#include <stdlib.h>
#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];
}