From 92f7e36083b28f43b7687d9aedfb922e9f466757 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Tue, 28 Mar 2023 18:42:04 +0100 Subject: [PATCH] st/oxr: Validate view array types --- src/xrt/state_trackers/oxr/oxr_api_session.c | 4 ++++ src/xrt/state_trackers/oxr/oxr_api_system.c | 4 ++++ src/xrt/state_trackers/oxr/oxr_api_verify.h | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/xrt/state_trackers/oxr/oxr_api_session.c b/src/xrt/state_trackers/oxr/oxr_api_session.c index 063c0980b..62cc030ec 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_session.c +++ b/src/xrt/state_trackers/oxr/oxr_api_session.c @@ -204,6 +204,10 @@ oxr_xrLocateViews(XrSession session, OXR_VERIFY_ARG_NOT_NULL(&log, views); } + for (uint32_t i = 0; i < viewCapacityInput; i++) { + OXR_VERIFY_ARG_ARRAY_ELEMENT_TYPE(&log, views, i, XR_TYPE_VIEW); + } + if (viewLocateInfo->displayTime <= (XrTime)0) { return oxr_error(&log, XR_ERROR_TIME_INVALID, "(time == %" PRIi64 ") is not a valid time.", viewLocateInfo->displayTime); diff --git a/src/xrt/state_trackers/oxr/oxr_api_system.c b/src/xrt/state_trackers/oxr/oxr_api_system.c index 7e68587ab..0347a8997 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_system.c +++ b/src/xrt/state_trackers/oxr/oxr_api_system.c @@ -156,6 +156,10 @@ oxr_xrEnumerateViewConfigurationViews(XrInstance instance, OXR_VERIFY_INSTANCE_AND_INIT_LOG(&log, instance, inst, "xrEnumerateViewConfigurationViews"); OXR_VERIFY_SYSTEM_AND_GET(&log, inst, systemId, sys); + for (uint32_t i = 0; i < viewCapacityInput; i++) { + OXR_VERIFY_ARG_ARRAY_ELEMENT_TYPE(&log, views, i, XR_TYPE_VIEW_CONFIGURATION_VIEW); + } + return oxr_system_enumerate_view_conf_views(&log, sys, viewConfigurationType, viewCapacityInput, viewCountOutput, views); } diff --git a/src/xrt/state_trackers/oxr/oxr_api_verify.h b/src/xrt/state_trackers/oxr/oxr_api_verify.h index 06db5ab8c..ed06d7911 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_verify.h +++ b/src/xrt/state_trackers/oxr/oxr_api_verify.h @@ -140,6 +140,19 @@ extern "C" { OXR_VERIFY_ARG_TYPE_CAN_BE_NULL(log, arg, type_enum); \ } while (false) +/*! + * Must only be used with full typed arrays, aka non-basetyped arrays like that + * passed into xrEnumerateSwapchainImages. + */ +#define OXR_VERIFY_ARG_ARRAY_ELEMENT_TYPE(log, array, index, type_enum) \ + do { \ + if ((array)[index].type != type_enum) { \ + return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, \ + "(" #array "[%u]->type == 0x%08x) expected 0x%08x", index, \ + (array)[index].type, type_enum); \ + } \ + } while (false) + #define OXR_VERIFY_SUBACTION_PATHS(log, count, paths) \ do { \ if (count > 0 && paths == NULL) { \