Subject: [PATCH] notes: do not access before the beginning of an array

From: Junio C Hamano <[email-masked]>
Date: Tue, 13 Jun 2023 18:10:49 -0700

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 <[email-masked]>
---
 * This time with a proposed log message with sign-off.

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

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");
-- 
2.41.0-28-gd7d8841f67