Fix ModifierSet buffer overrun

This commit is contained in:
Vftdan 2024-08-17 14:47:22 +02:00
parent 20a97dbba7
commit 4f71351796
1 changed files with 9 additions and 0 deletions

View File

@ -54,6 +54,9 @@ modifier_set_set_from(ModifierSet * target, const ModifierSet source)
{ {
modifier_set_extend(target, source.byte_length); modifier_set_extend(target, source.byte_length);
for (size_t i = 0; i < target->byte_length; ++i) { for (size_t i = 0; i < target->byte_length; ++i) {
if (i >= source.byte_length) {
return;
}
target->bits[i] |= source.bits[i]; target->bits[i] |= source.bits[i];
} }
} }
@ -62,6 +65,9 @@ __attribute__((unused)) inline static void
modifier_set_unset_from(ModifierSet * target, const ModifierSet source) modifier_set_unset_from(ModifierSet * target, const ModifierSet source)
{ {
for (size_t i = 0; i < target->byte_length; ++i) { for (size_t i = 0; i < target->byte_length; ++i) {
if (i >= source.byte_length) {
return;
}
target->bits[i] &= ~source.bits[i]; target->bits[i] &= ~source.bits[i];
} }
} }
@ -71,6 +77,9 @@ modifier_set_toggle_from(ModifierSet * target, const ModifierSet source)
{ {
modifier_set_extend(target, source.byte_length); modifier_set_extend(target, source.byte_length);
for (size_t i = 0; i < target->byte_length; ++i) { for (size_t i = 0; i < target->byte_length; ++i) {
if (i >= source.byte_length) {
return;
}
target->bits[i] ^= source.bits[i]; target->bits[i] ^= source.bits[i];
} }
} }