Commit 78afc55d authored by Jakob Bornecrantz's avatar Jakob Bornecrantz Committed by Ryan Pavlik

st/oxr: Improve the fixed size single path verifier

parent 9b3b3704
Pipeline #29174 passed with stages
in 59 seconds
......@@ -136,10 +136,13 @@ extern "C" {
*
*/
/*!
* Verify a single path level that sits inside of a fixed sized array.
*/
XrResult
oxr_verify_fixed_size_single_level_path(struct oxr_logger*,
const char* path,
uint32_t size,
uint32_t array_size,
const char* name);
XrResult
......
......@@ -9,7 +9,8 @@
* @ingroup oxr_api
*/
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include "xrt/xrt_compiler.h"
#include "util/u_debug.h"
......@@ -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
contains_zero(const char* path, uint32_t size)
{
......@@ -40,10 +59,10 @@ contains_zero(const char* path, uint32_t size)
extern "C" XrResult
oxr_verify_fixed_size_single_level_path(struct oxr_logger* log,
const char* path,
uint32_t size,
uint32_t array_size,
const char* name)
{
if (size == 0) {
if (array_size == 0) {
return oxr_error(log, XR_ERROR_VALIDATION_FAILURE,
"(%s) internal runtime error", name);
}
......@@ -53,13 +72,26 @@ oxr_verify_fixed_size_single_level_path(struct oxr_logger* log,
"(%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,
"(%s) must include zero termination '\\0'.",
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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment