List for cgit developers and users
 help / color / mirror / Atom feed
From: lemon <lsof@mailbox.org>
To: cgit@lists.zx2c4.com
Cc: lemon <lsof@mailbox.org>
Subject: [PATCH] html: fix fmt() off-by-one error
Date: Tue,  8 Feb 2022 12:37:45 +0100	[thread overview]
Message-ID: <20220208113745.13748-1-lsof@mailbox.org> (raw)

vsnprintf returns the byte count of the formatted output not including
the null terminator, so in the case that len == 1024 the last character
of the output was being truncated and not detected by the later check.
Changing the greater than comparison to greater than or equal fixes this
edge case.
---
 html.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/html.c b/html.c
index 7f81965..0bac34b 100644
--- a/html.c
+++ b/html.c
@@ -59,7 +59,7 @@ char *fmt(const char *format, ...)
 	va_start(args, format);
 	len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
 	va_end(args);
-	if (len > sizeof(buf[bufidx])) {
+	if (len >= sizeof(buf[bufidx])) {
 		fprintf(stderr, "[html.c] string truncated: %s\n", format);
 		exit(1);
 	}
-- 
2.35.1


             reply	other threads:[~2022-02-08 11:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-08 11:37 lemon [this message]
2022-02-08 12:38 ` Christian Hesse
2022-02-08 12:39   ` Jason A. Donenfeld
2022-02-08 17:03     ` Christian Hesse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220208113745.13748-1-lsof@mailbox.org \
    --to=lsof@mailbox.org \
    --cc=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).