]> git.ipfire.org Git - thirdparty/git.git/commit - attr.c
attr: fix integer overflow with more than INT_MAX macros
authorPatrick Steinhardt <ps@pks.im>
Thu, 1 Dec 2022 14:45:36 +0000 (15:45 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 5 Dec 2022 06:14:16 +0000 (15:14 +0900)
commite1e12e97ac73ded85f7d000da1063a774b3cc14f
tree66e22e31853435c667234bb0ede40e728203e115
parent447ac906e189535e77dcb1f4bbe3f1bc917d4c12
attr: fix integer overflow with more than INT_MAX macros

Attributes have a field that tracks the position in the `all_attrs`
array they're stored inside. This field gets set via `hashmap_get_size`
when adding the attribute to the global map of attributes. But while the
field is of type `int`, the value returned by `hashmap_get_size` is an
`unsigned int`. It can thus happen that the value overflows, where we
would now dereference teh `all_attrs` array at an out-of-bounds value.

We do have a sanity check for this overflow via an assert that verifies
the index matches the new hashmap's size. But asserts are not a proper
mechanism to detect against any such overflows as they may not in fact
be compiled into production code.

Fix this by using an `unsigned int` to track the index and convert the
assert to a call `die()`.

Reported-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
attr.c