]> git.ipfire.org Git - thirdparty/git.git/commitdiff
notes: don't access hash of NULL object_id pointer
authorRené Scharfe <l.s.r@web.de>
Sat, 15 Jul 2017 18:15:26 +0000 (20:15 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 17 Jul 2017 21:51:07 +0000 (14:51 -0700)
Check if note is NULL, as we already do for different purposes a few
lines above, and pass a NULL pointer to prepare_note_data() in that
case instead of trying to access the hash member.

Found with Clang's UBSan.

Signed-off-by: Rene Scharfe <l.s.r@web.de>
Acked-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/notes.c

index 2ebc2b7c43f433648f1156129f209747fbd6e184..3d9dbc97a1dd53c8baa20c39bcdb06e43b1c9e32 100644 (file)
@@ -453,7 +453,7 @@ static int add(int argc, const char **argv, const char *prefix)
                        oid_to_hex(&object));
        }
 
-       prepare_note_data(&object, &d, note->hash);
+       prepare_note_data(&object, &d, note ? note->hash : NULL);
        if (d.buf.len || allow_empty) {
                write_note_data(&d, new_note.hash);
                if (add_note(t, &object, &new_note, combine_notes_overwrite))