]> git.ipfire.org Git - thirdparty/git.git/commit
reftable/stack: fix parameter validation when compacting range
authorPatrick Steinhardt <ps@pks.im>
Tue, 6 Feb 2024 06:35:31 +0000 (07:35 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 6 Feb 2024 20:10:08 +0000 (12:10 -0800)
commitca63af0a248d31bf917d207722b284da41ffcee7
tree44641c8942ae97300fae36bcea3c60a1d7d1ff28
parentb4ff12c8eefff9cba73ba3cb7492111adfa31d87
reftable/stack: fix parameter validation when compacting range

The `stack_compact_range()` function receives a "first" and "last" index
that indicates which tables of the reftable stack should be compacted.
Naturally, "first" must be smaller than "last" in order to identify a
proper range of tables to compress, which we indeed also assert in the
function. But the validations happens after we have already allocated
arrays with a size of `last - first + 1`, leading to an underflow and
thus an invalid allocation size.

Fix this by reordering the array allocations to happen after we have
validated parameters. While at it, convert the array allocations to use
the newly introduced macros.

Note that the relevant variables pointing into arrays should also be
converted to use `size_t` instead of `int`. This is left for a later
commit in this series.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
reftable/stack.c