{"thread":{"id":"46728","subject":"[PATCH] load_subtree(): check that `prefix_len` is in the expected range","startedAt":"2017-09-08T16:11:03Z","lastAt":"2017-09-08T16:11:03Z","messageCount":1,"participants":["Michael Haggerty"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"327784","messageId":"ca6046b8b955df6a798b690fdecb0b8ba47d57a9.1504886586.git.mhagger@alum.mit.edu","threadId":"46728","inReplyTo":null,"subject":"[PATCH] load_subtree(): check that `prefix_len` is in the expected range","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-09-08T16:10:10Z","receivedAt":"2017-09-08T16:11:03Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"This value, which is stashed in the last byte of an object_id hash,\ngets handed around a lot. So add a sanity check before using it in\n`load_subtree()`.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\nThis patch is an addendum to v1 of the mh/notes-cleanup patch series\n[1]. It adds the assertion that was suggested by Junio [2].\n\nSince the first patch series is already in next, this patch is\nconstructed to apply on top of that branch.\n\nThanks to Junio and Johan for their review of v1.\n\nMichael\n\n[1] https://public-inbox.org/git/cover.1503734566.git.mhagger@alum.mit.edu/\n[2] https://public-inbox.org/git/xmqqh8wuqo6e.fsf@gitster.mtv.corp.google.com/\n\n notes.c | 5 ++++-\n 1 file changed, 4 insertions(+), 1 deletion(-)\n\ndiff --git a/notes.c b/notes.c\nindex 40d9ba6252..27d232f294 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -417,7 +417,10 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,\n \t\t     oid_to_hex(&subtree->val_oid));\n \n \tprefix_len = subtree->key_oid.hash[KEY_INDEX];\n-\tassert(prefix_len * 2 >= n);\n+\tif (prefix_len >= GIT_SHA1_RAWSZ)\n+\t\tBUG(\"prefix_len (%\"PRIuMAX\") is out of range\", (uintmax_t)prefix_len);\n+\tif (prefix_len * 2 < n)\n+\t\tBUG(\"prefix_len (%\"PRIuMAX\") is too small\", (uintmax_t)prefix_len);\n \tmemcpy(object_oid.hash, subtree->key_oid.hash, prefix_len);\n \twhile (tree_entry(&desc, &entry)) {\n \t\tunsigned char type;\n-- \n2.14.1\n\n"}]}