]> dgit.raspbian.org Git - dovecot.git/commitdiff
[PATCH 2/4] lib-mail: o_stream_dot_sendv() - Fix boundary off by one
authorMarco Bettini <marco.bettini@open-xchange.com>
Mon, 20 Apr 2026 09:50:54 +0000 (09:50 +0000)
committerNoah Meyerhans <noahm@debian.org>
Wed, 16 Sep 2026 19:06:35 +0000 (15:06 -0400)
Gbp-Pq: Name 0002-lib-mail-o_stream_dot_sendv-Fix-boundary-off-by-one.patch

src/lib-mail/ostream-dot.c
src/lib-mail/test-ostream-dot.c

index 6bc9aa23d3409adcfc0b81014a643af47c419c2f..9d5411abb46bba9d92b428875afdef8a7c6a859b 100644 (file)
@@ -105,7 +105,7 @@ o_stream_dot_sendv(struct ostream_private *stream,
 
                p = data;
                pend = CONST_PTR_OFFSET(data, size);
-               for (; p < pend && (size_t)(p-data)+2 < max_bytes; p++) {
+               for (; p < pend && ((size_t)(p - data) + 2) <= max_bytes; p++) {
                        char add = 0;
 
                        size = pend - p;
index 9ddb563cee8f2a1fc72d42e21af85c04ecdbb729..6a1813d2469e5480a60fdafee374d07141f8990f 100644 (file)
@@ -92,11 +92,34 @@ static void test_ostream_dot_parent_almost_full(void)
        test_end();
 }
 
+static void test_ostream_dot_parent_exact_fit(void)
+{
+       buffer_t *output_data;
+       struct ostream *test_output, *output;
+       ssize_t ret;
+
+       test_begin("dot ostream parent exact fit");
+       output_data = t_buffer_create(1024);
+       test_output = test_ostream_create_nonblocking(output_data, 2);
+       test_ostream_set_max_output_size(test_output, 2);
+
+       output = o_stream_create_dot(test_output, FALSE);
+       ret = o_stream_send(output, ".", 1);
+       test_assert(ret == 1);
+       test_assert_ucmp(output_data->used, ==, 2);
+       test_assert_memcmp(output_data->data, output_data->used, "..", 2);
+
+       o_stream_unref(&output);
+       o_stream_unref(&test_output);
+       test_end();
+}
+
 int main(void)
 {
        static void (*const test_functions[])(void) = {
                test_ostream_dot,
                test_ostream_dot_parent_almost_full,
+               test_ostream_dot_parent_exact_fit,
                NULL
        };
        return test_run(test_functions);