diff mbox series

notes: do not access before the beginning of an array

Message ID xmqqbkhi26hy.fsf_-_@gitster.g (mailing list archive)
State Accepted
Commit 657f3e2bf7e3fcc156f4048386aabe11309f9610
Headers show
Series notes: do not access before the beginning of an array | expand

Commit Message

Junio C Hamano June 14, 2023, 1:10 a.m. UTC
The check to see if the last byte of the separator string is a LF
makes sense *only* when the separator string is known to be non
empty.  This has been breaking the asan/ubsan job at CI.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * This time with a proposed log message with sign-off.

 builtin/notes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/builtin/notes.c b/builtin/notes.c
index 6eede30597..785b1922ad 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -239,7 +239,7 @@  static void write_note_data(struct note_data *d, struct object_id *oid)
 
 static void append_separator(struct strbuf *message)
 {
-	if (separator[strlen(separator) - 1] == '\n')
+	if (*separator && separator[strlen(separator) - 1] == '\n')
 		strbuf_addstr(message, separator);
 	else
 		strbuf_addf(message, "%s%s", separator, "\n");