about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorlemon2022-02-08 12:37:45 +0100
committerJune McEnroe2022-02-18 00:00:57 +0000
commitc5809a4296f852fe30a7356854d3d0758fa1bf7f (patch)
tree03a60ac0f03abae8795a1abe03ce045fa4de53dc
parentAllow to give readme head from query (diff)
downloadcgit-c5809a4296f852fe30a7356854d3d0758fa1bf7f.tar.gz
cgit-c5809a4296f852fe30a7356854d3d0758fa1bf7f.zip
Fix fmt() off-by-one error
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.
-rw-r--r--html.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/html.c b/html.c index cefcf5e..ced781a 100644 --- a/html.c +++ b/html.c
@@ -59,7 +59,7 @@ char *fmt(const char *format, ...)
59 va_start(args, format); 59 va_start(args, format);
60 len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args); 60 len = vsnprintf(buf[bufidx], sizeof(buf[bufidx]), format, args);
61 va_end(args); 61 va_end(args);
62 if (len > sizeof(buf[bufidx])) { 62 if (len >= sizeof(buf[bufidx])) {
63 fprintf(stderr, "[html.c] string truncated: %s\n", format); 63 fprintf(stderr, "[html.c] string truncated: %s\n", format);
64 exit(1); 64 exit(1);
65 } 65 }