]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: buffer - Assert that we don't try to allocate SIZE_MAX buffer
authorAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 11 Aug 2020 06:00:17 +0000 (09:00 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 11 Sep 2020 07:07:20 +0000 (07:07 +0000)
Only if devel checks are enabled

src/lib/buffer.c

index 316771802b366c06d8e11748201915b65b043d68..28a24c1995d12fb0f62ff8caa8b72d8c7f256e20 100644 (file)
@@ -134,6 +134,15 @@ buffer_t *buffer_create_dynamic(pool_t pool, size_t init_size)
 {
        struct real_buffer *buf;
 
+#ifdef DEBUG
+       /* we increment this by 1 later on, so if it's SIZE_MAX
+          it turns into 0 and hides a potential bug.
+
+          Too scary to use in production for now, though. This
+          can change in future. */
+       i_assert(init_size < SIZE_MAX);
+#endif
+
        buf = p_new(pool, struct real_buffer, 1);
        buf->pool = pool;
        buf->dynamic = TRUE;