st/oxr: Do not crash on too many bindings to an action

This commit is contained in:
Jakob Bornecrantz 2024-01-04 21:18:16 +00:00
parent 170131bd2b
commit 0f9147c6de
3 changed files with 27 additions and 13 deletions

View file

@ -426,18 +426,22 @@ void
oxr_binding_find_bindings_from_key(struct oxr_logger *log,
struct oxr_interaction_profile *p,
uint32_t key,
struct oxr_binding *bindings[OXR_MAX_BINDINGS_PER_ACTION],
size_t *binding_count)
size_t max_bounding_count,
struct oxr_binding **bindings,
size_t *out_binding_count)
{
if (p == NULL) {
*binding_count = 0;
*out_binding_count = 0;
return;
}
//! @todo This function should be a two call function, or handle more
//! then 32 bindings.
// How many bindings are we returning?
size_t num = 0;
/*
* Loop over all app provided bindings for this profile
* and return those matching the action.
*/
for (size_t y = 0; y < p->binding_count; y++) {
struct oxr_binding *b = &p->bindings[y];
@ -448,13 +452,16 @@ oxr_binding_find_bindings_from_key(struct oxr_logger *log,
}
}
if (num >= 32) {
*binding_count = num;
return;
//! @todo Should return total count instead of fixed max.
if (num >= max_bounding_count) {
oxr_warn(log, "Internal limit reached, action has too many bindings!");
break;
}
}
*binding_count = num;
assert(num <= max_bounding_count);
*out_binding_count = num;
}
struct oxr_interaction_profile *

View file

@ -684,7 +684,13 @@ get_binding(struct oxr_logger *log,
}
size_t num = 0;
oxr_binding_find_bindings_from_key(log, profile, act_ref->act_key, binding_points, &num);
oxr_binding_find_bindings_from_key( //
log, // log
profile, // p
act_ref->act_key, // key
ARRAY_SIZE(binding_points), // max_bounding_count
binding_points, // bindings
&num); // out_binding_count
if (num == 0) {
oxr_slog(slog, "\t\t\tNo bindings!\n");
return;

View file

@ -589,10 +589,11 @@ oxr_session_binding_destroy_all(struct oxr_logger *log, struct oxr_session *sess
*/
void
oxr_binding_find_bindings_from_key(struct oxr_logger *log,
struct oxr_interaction_profile *profile,
struct oxr_interaction_profile *p,
uint32_t key,
struct oxr_binding *bindings[OXR_MAX_BINDINGS_PER_ACTION],
size_t *binding_count);
size_t max_bounding_count,
struct oxr_binding **bindings,
size_t *out_binding_count);
/*!
* @public @memberof oxr_instance