* [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
* Re: [PATCH] html: fix fmt() off-by-one error 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 0 siblings, 1 reply; 4+ messages in thread From: Christian Hesse @ 2022-02-08 12:38 UTC (permalink / raw) To: lemon; +Cc: cgit [-- Attachment #1: Type: text/plain, Size: 730 bytes --] lemon <lsof@mailbox.org> on Tue, 2022/02/08 12:37: > 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. We already have that pending... https://git.zx2c4.com/cgit/commit/?h=ch/html-fmt&id=d828a623442e3fc3159e2c188a78e6fd4aca8af4 -- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Best regards my address: */=0;b=c[a++];) putchar(b-1/(/* Chris cc -ox -xc - && ./x */b/42*2-3)*42);} [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] html: fix fmt() off-by-one error 2022-02-08 12:38 ` Christian Hesse @ 2022-02-08 12:39 ` Jason A. Donenfeld 2022-02-08 17:03 ` Christian Hesse 0 siblings, 1 reply; 4+ messages in thread From: Jason A. Donenfeld @ 2022-02-08 12:39 UTC (permalink / raw) To: Christian Hesse; +Cc: lemon, cgit Thanks guys. I'll get these merged to master branch in the coming two weeks and cut a new release. Jason ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] html: fix fmt() off-by-one error 2022-02-08 12:39 ` Jason A. Donenfeld @ 2022-02-08 17:03 ` Christian Hesse 0 siblings, 0 replies; 4+ messages in thread From: Christian Hesse @ 2022-02-08 17:03 UTC (permalink / raw) To: Jason A. Donenfeld; +Cc: cgit [-- Attachment #1: Type: text/plain, Size: 503 bytes --] "Jason A. Donenfeld" <Jason@zx2c4.com> on Tue, 2022/02/08 13:39: > Thanks guys. I'll get these merged to master branch in the coming two > weeks and cut a new release. That would be great, much appreciated! /me hopes for review and merge of dynamic aging... -- main(a){char*c=/* Schoene Gruesse */"B?IJj;MEH" "CX:;",b;for(a/* Best regards my address: */=0;b=c[a++];) putchar(b-1/(/* Chris cc -ox -xc - && ./x */b/42*2-3)*42);} [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 488 bytes --] ^ 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).