List for cgit developers and users
 help / color / mirror / Atom feed
* [PATCH] html: fix fmt() off-by-one error
@ 2022-02-08 11:37 lemon
  2022-02-08 12:38 ` Christian Hesse
  0 siblings, 1 reply; 4+ messages in thread
From: lemon @ 2022-02-08 11:37 UTC (permalink / raw)
  To: cgit; +Cc: lemon

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-08 17:03 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 11:37 [PATCH] html: fix fmt() off-by-one error lemon
2022-02-08 12:38 ` Christian Hesse
2022-02-08 12:39   ` Jason A. Donenfeld
2022-02-08 17:03     ` Christian Hesse

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).