This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit 4f79cc0b5abfae11bb2924dd62535d8389dc4fc8
Author: Boris Faure <[email protected]>
AuthorDate: Thu Nov 5 21:21:32 2026 +0000

    sb: count the NUL when sizing the buffer
    
    ty_sb_add() sized a new allocation from the content alone, so a
    zero-length add to an empty buffer allocated zero bytes and then wrote
    the terminating NUL one byte past them. Found by the colour parser
    fuzzer on an empty input.
---
 src/bin/sb.c         | 21 ++++++++++++++++++++-
 src/bin/tytest.c     |  1 +
 src/bin/unit_tests.h |  1 +
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/src/bin/sb.c b/src/bin/sb.c
index cceb4465..c79e5965 100644
--- a/src/bin/sb.c
+++ b/src/bin/sb.c
@@ -18,7 +18,7 @@ ty_sb_add(struct ty_sb *sb, const char *s, size_t len)
 
    if ((new_len + sb->gap >= sb->alloc) || !sb->buf)
      {
-        size_t new_alloc = ((new_len + sb->gap + 15) / 16) * 24;
+        size_t new_alloc = ((new_len + sb->gap + 1 + 15) / 16) * 24;
         char *new_buf;
         char *buf = sb->buf;
 
@@ -174,6 +174,25 @@ ty_sb_free(struct ty_sb *sb)
 }
 
 #if defined(BINARY_TYTEST)
+int
+tytest_sb_add(void)
+{
+   struct ty_sb sb = {};
+
+   /* an empty add still allocates room for the NUL */
+   assert(ty_sb_add(&sb, "", 0) == 0);
+   assert(sb.buf && sb.len == 0 && sb.alloc > sb.len);
+   assert(sb.buf[0] == '\0');
+
+   assert(ty_sb_add(&sb, "foo", 3) == 0);
+   assert(ty_sb_add(&sb, "", 0) == 0);
+   assert(sb.len == 3 && sb.alloc > sb.len);
+   assert(strcmp(sb.buf, "foo") == 0);
+   ty_sb_free(&sb);
+
+   return 0;
+}
+
 int
 tytest_sb_skip(void)
 {
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 253565d0..f357ad63 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -40,6 +40,7 @@ static struct {
 #if defined(HAVE_TEXTGRID_RGB)
        { "truecolor_render", tytest_truecolor_render},
 #endif
+       { "sb_add", tytest_sb_add},
        { "sb_skip", tytest_sb_skip},
        { "sb_trim", tytest_sb_trim},
        { "sb_gap", tytest_sb_gap},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index c3b103b7..11cd94d8 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -14,6 +14,7 @@ int tytest_cell_is_empty_rgb(void);
 #if defined(HAVE_TEXTGRID_RGB)
 int tytest_truecolor_render(void);
 #endif
+int tytest_sb_add(void);
 int tytest_sb_skip(void);
 int tytest_sb_trim(void);
 int tytest_sb_gap(void);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to