From: Aki Tuomi Date: Tue, 11 Aug 2020 06:00:17 +0000 (+0300) Subject: lib: buffer - Assert that we don't try to allocate SIZE_MAX buffer X-Git-Tag: 2.3.13~208 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acba0e7c3db5dad4b2c70141506c4eb5bd42d6f2;p=thirdparty%2Fdovecot%2Fcore.git lib: buffer - Assert that we don't try to allocate SIZE_MAX buffer Only if devel checks are enabled --- diff --git a/src/lib/buffer.c b/src/lib/buffer.c index 316771802b..28a24c1995 100644 --- a/src/lib/buffer.c +++ b/src/lib/buffer.c @@ -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;