Skip to content

Commit 3964281

Browse files
mhaggergitster
authored andcommitted
load_subtree(): check that prefix_len is in the expected range
This value, which is stashed in the last byte of an object_id hash, gets handed around a lot. So add a sanity check before using it in `load_subtree()`. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 06cfa75 commit 3964281

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

notes.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,10 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
417417
oid_to_hex(&subtree->val_oid));
418418

419419
prefix_len = subtree->key_oid.hash[KEY_INDEX];
420-
assert(prefix_len * 2 >= n);
420+
if (prefix_len >= GIT_SHA1_RAWSZ)
421+
BUG("prefix_len (%"PRIuMAX") is out of range", (uintmax_t)prefix_len);
422+
if (prefix_len * 2 < n)
423+
BUG("prefix_len (%"PRIuMAX") is too small", (uintmax_t)prefix_len);
421424
memcpy(object_oid.hash, subtree->key_oid.hash, prefix_len);
422425
while (tree_entry(&desc, &entry)) {
423426
unsigned char type;

0 commit comments

Comments
 (0)