mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2024-12-28 02:26:16 +00:00
st/oxr: Fix localized name validation
This commit is contained in:
parent
81fc9587db
commit
a776b94147
|
@ -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.
|
||||
|
|
|
@ -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*,
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue