summaryrefslogtreecommitdiff
path: root/builtin/notes.c
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2024-02-05 14:35:53 +0000
committerJunio C Hamano <gitster@pobox.com>2024-02-06 10:42:28 -0800
commit568459bf5e97a4f61429e3bdd1f97b54b39a1383 (patch)
tree7b17660c5d8aecf25dc3060c5c80ffa19d7b22c1 /builtin/notes.c
parent564d0252ca632e0264ed670534a51d18a689ef5d (diff)
Always check the return value of `repo_read_object_file()`
There are a couple of places in Git's source code where the return value is not checked. As a consequence, they are susceptible to segmentation faults. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/notes.c')
-rw-r--r--builtin/notes.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/builtin/notes.c b/builtin/notes.c
index 9f38863dd5..40543862d3 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -718,9 +718,11 @@ static int append_edit(int argc, const char **argv, const char *prefix)
struct strbuf buf = STRBUF_INIT;
char *prev_buf = repo_read_object_file(the_repository, note, &type, &size);
- if (prev_buf && size)
+ if (!prev_buf)
+ die(_("unable to read %s"), oid_to_hex(note));
+ if (size)
strbuf_add(&buf, prev_buf, size);
- if (d.buf.len && prev_buf && size)
+ if (d.buf.len && size)
append_separator(&buf);
strbuf_insert(&d.buf, 0, buf.buf, buf.len);