st/oxr: Validate view array types

This commit is contained in:
Jakob Bornecrantz 2023-03-28 18:42:04 +01:00
parent 7e96a1c557
commit 92f7e36083
3 changed files with 21 additions and 0 deletions

View file

@ -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);

View file

@ -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);
}

View file

@ -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) { \