Skip to content
Snippets Groups Projects
Commit 78afc55d authored by Jakob Bornecrantz's avatar Jakob Bornecrantz Committed by Ryan Pavlik
Browse files

st/oxr: Improve the fixed size single path verifier

parent 9b3b3704
Branches
No related tags found
No related merge requests found
...@@ -136,10 +136,13 @@ extern "C" { ...@@ -136,10 +136,13 @@ extern "C" {
* *
*/ */
/*!
* Verify a single path level that sits inside of a fixed sized array.
*/
XrResult XrResult
oxr_verify_fixed_size_single_level_path(struct oxr_logger*, oxr_verify_fixed_size_single_level_path(struct oxr_logger*,
const char* path, const char* path,
uint32_t size, uint32_t array_size,
const char* name); const char* name);
XrResult XrResult
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
* @ingroup oxr_api * @ingroup oxr_api
*/ */
#include <stdio.h> #include <cstdio>
#include <cstring>
#include "xrt/xrt_compiler.h" #include "xrt/xrt_compiler.h"
#include "util/u_debug.h" #include "util/u_debug.h"
...@@ -25,6 +26,24 @@ ...@@ -25,6 +26,24 @@
* *
*/ */
static bool
valid_path_char(const char c)
{
if ('a' <= c && c <= 'z') {
return true;
}
if ('0' <= c && c <= '9') {
return true;
}
if (c == '-' || c == '_' || c == '.' || c == '/') {
return true;
}
return false;
}
static bool static bool
contains_zero(const char* path, uint32_t size) contains_zero(const char* path, uint32_t size)
{ {
...@@ -40,10 +59,10 @@ contains_zero(const char* path, uint32_t size) ...@@ -40,10 +59,10 @@ contains_zero(const char* path, uint32_t size)
extern "C" XrResult extern "C" XrResult
oxr_verify_fixed_size_single_level_path(struct oxr_logger* log, oxr_verify_fixed_size_single_level_path(struct oxr_logger* log,
const char* path, const char* path,
uint32_t size, uint32_t array_size,
const char* name) const char* name)
{ {
if (size == 0) { if (array_size == 0) {
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
"(%s) internal runtime error", name); "(%s) internal runtime error", name);
} }
...@@ -53,13 +72,26 @@ oxr_verify_fixed_size_single_level_path(struct oxr_logger* log, ...@@ -53,13 +72,26 @@ oxr_verify_fixed_size_single_level_path(struct oxr_logger* log,
"(%s) can not be empty", name); "(%s) can not be empty", name);
} }
if (!contains_zero(path, size)) { if (!contains_zero(path, array_size)) {
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
"(%s) must include zero termination '\\0'.", "(%s) must include zero termination '\\0'.",
name); name);
} }
//! @todo verify more! size_t length = strlen(path);
for (size_t i = 0; i < length; i++) {
const char c = path[i];
// Slashes are not valid in single level paths.
if (valid_path_char(c) && c != '/') {
continue;
}
return oxr_error(
log, XR_ERROR_VALIDATION_FAILURE,
"(%s) 0x%02x is not a valid character at position %u", name,
c, (uint32_t)i);
}
return XR_SUCCESS; return XR_SUCCESS;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment