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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 * 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




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux