Merge branch 'mh/notes-cleanup' into next
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 Sep 2017 08:28:03 +0000 (17:28 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Sep 2017 08:28:03 +0000 (17:28 +0900)
Code clean-up.

* mh/notes-cleanup:
load_subtree(): check that `prefix_len` is in the expected range

1  2 
notes.c
diff --combined notes.c
index 7f5bfa19c7d49e09b54c5f5e2a6373dbb7451500,27d232f294d514113613031ac4f18d8d3d19311f..5c62862574399acb486530d3fab5a7f659eb7c2f
+++ b/notes.c
@@@ -411,13 -411,16 +411,16 @@@ static void load_subtree(struct notes_t
        struct tree_desc desc;
        struct name_entry entry;
  
 -      buf = fill_tree_descriptor(&desc, subtree->val_oid.hash);
 +      buf = fill_tree_descriptor(&desc, &subtree->val_oid);
        if (!buf)
                die("Could not read %s for notes-index",
                     oid_to_hex(&subtree->val_oid));
  
        prefix_len = subtree->key_oid.hash[KEY_INDEX];
-       assert(prefix_len * 2 >= n);
+       if (prefix_len >= GIT_SHA1_RAWSZ)
+               BUG("prefix_len (%"PRIuMAX") is out of range", (uintmax_t)prefix_len);
+       if (prefix_len * 2 < n)
+               BUG("prefix_len (%"PRIuMAX") is too small", (uintmax_t)prefix_len);
        memcpy(object_oid.hash, subtree->key_oid.hash, prefix_len);
        while (tree_entry(&desc, &entry)) {
                unsigned char type;
@@@ -1022,7 -1025,7 +1025,7 @@@ void init_notes(struct notes_tree *t, c
        t->dirty = 0;
  
        if (flags & NOTES_INIT_EMPTY || !notes_ref ||
 -          get_sha1_treeish(notes_ref, object_oid.hash))
 +          get_oid_treeish(notes_ref, &object_oid))
                return;
        if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))
                die("Cannot use notes ref %s", notes_ref);