From a776b94147adbc3fb0e50b4c10ee0da2e5ffd12e Mon Sep 17 00:00:00 2001 From: Benjamin Saunders Date: Sat, 13 Apr 2019 08:11:47 -0700 Subject: [PATCH] st/oxr: Fix localized name validation --- src/xrt/state_trackers/oxr/oxr_api_action.c | 4 ++-- src/xrt/state_trackers/oxr/oxr_api_verify.h | 17 ++++++++++++++ src/xrt/state_trackers/oxr/oxr_verify.cpp | 26 +++++++++++++++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) diff --git a/src/xrt/state_trackers/oxr/oxr_api_action.c b/src/xrt/state_trackers/oxr/oxr_api_action.c index 7b4e3ad9e..23f93f176 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_action.c +++ b/src/xrt/state_trackers/oxr/oxr_api_action.c @@ -137,8 +137,7 @@ oxr_xrCreateActionSet(XrSession session, OXR_VERIFY_ARG_NOT_NULL(&log, actionSet); OXR_VERIFY_ARG_SINGLE_LEVEL_FIXED_LENGTH_PATH( &log, createInfo->actionSetName); - OXR_VERIFY_ARG_SINGLE_LEVEL_FIXED_LENGTH_PATH( - &log, createInfo->localizedActionSetName); + OXR_VERIFY_ARG_LOCALIZED_NAME(&log, createInfo->localizedActionSetName); //! @todo Move to oxr_action.h and implement more fully. struct oxr_action_set* act_set = NULL; @@ -190,6 +189,7 @@ oxr_xrCreateAction(XrActionSet actionSet, "xrCreateAction"); OXR_VERIFY_ARG_TYPE_AND_NULL(&log, createInfo, XR_TYPE_ACTION_CREATE_INFO); + OXR_VERIFY_ARG_LOCALIZED_NAME(&log, createInfo->localizedActionName); OXR_VERIFY_ARG_NOT_NULL(&log, action); //! @todo Move to oxr_action.h and implement more fully. diff --git a/src/xrt/state_trackers/oxr/oxr_api_verify.h b/src/xrt/state_trackers/oxr/oxr_api_verify.h index f9d82c63e..ac4c9e145 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_verify.h +++ b/src/xrt/state_trackers/oxr/oxr_api_verify.h @@ -130,6 +130,14 @@ extern "C" { } \ } while (false) +#define OXR_VERIFY_ARG_LOCALIZED_NAME(log, string) \ + do { \ + XrResult verify_ret = oxr_verify_localized_name( \ + log, string, ARRAY_SIZE(string), #string); \ + if (verify_ret != XR_SUCCESS) { \ + return verify_ret; \ + } \ + } while (false) /* * @@ -162,6 +170,15 @@ oxr_verify_fixed_size_single_level_path(struct oxr_logger*, uint32_t array_size, const char* name); +/*! + * Verify an arbitrary UTF-8 string that sits inside of a fixed sized array. + */ +XrResult +oxr_verify_localized_name(struct oxr_logger*, + const char* string, + uint32_t array_size, + const char* name); + XrResult oxr_verify_XrSessionCreateInfo(struct oxr_logger*, const struct oxr_instance*, diff --git a/src/xrt/state_trackers/oxr/oxr_verify.cpp b/src/xrt/state_trackers/oxr/oxr_verify.cpp index 8db0a7865..c42d09103 100644 --- a/src/xrt/state_trackers/oxr/oxr_verify.cpp +++ b/src/xrt/state_trackers/oxr/oxr_verify.cpp @@ -96,6 +96,32 @@ oxr_verify_fixed_size_single_level_path(struct oxr_logger* log, return XR_SUCCESS; } +extern "C" XrResult +oxr_verify_localized_name(struct oxr_logger* log, + const char* string, + uint32_t array_size, + const char* name) +{ + if (array_size == 0) { + return oxr_error(log, XR_ERROR_RUNTIME_FAILURE, + "(%s) internal runtime error", name); + } + + if (string[0] == '\0') { + return oxr_error(log, XR_ERROR_NAME_INVALID, + "(%s) can not be empty", name); + } + + if (!contains_zero(string, array_size)) { + return oxr_error(log, XR_ERROR_NAME_INVALID, + "(%s) must include zero termination '\\0'.", + name); + } + + // Future work: validate well-formed UTF-8? + return XR_SUCCESS; +} + enum class State { Start,