summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQualys Security Advisory <qsa@qualys.com>2021-02-21 19:40:21 -0800
committerHeiko Schlittermann (HS12-RIPE) <hs@schlittermann.de>2021-04-30 22:42:17 +0200
commit5fd6af5815401dc60e8fe4309258911aa41d3013 (patch)
treea519d17d4def2fb271968ff2d1550ba95f16b7a3
parent0f6c3d3f7efb5d66dabf69c36e06912d89ff96fc (diff)
downloadexim4-5fd6af5815401dc60e8fe4309258911aa41d3013.tar.gz
Security: Refuse negative and large store allocations
Based on Phil Pennock's commits b34d3046 and e6c1606a.
-rw-r--r--src/src/store.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/src/store.c b/src/src/store.c
index b52799132..a2a80f631 100644
--- a/src/src/store.c
+++ b/src/src/store.c
@@ -128,6 +128,12 @@ Returns: pointer to store (panic on malloc failure)
void *
store_get_3(int size, const char *filename, int linenumber)
{
+if (size < 0 || size > INT_MAX/2)
+ {
+ log_write(0, LOG_MAIN|LOG_PANIC_DIE,
+ "bad memory allocation requested (%d bytes)",
+ size);
+ }
/* Round up the size to a multiple of the alignment. Although this looks a
messy statement, because "alignment" is a constant expression, the compiler can
do a reasonable job of optimizing, especially if the value of "alignment" is a
@@ -270,6 +276,13 @@ store_extend_3(void *ptr, int oldsize, int newsize, const char *filename,
int inc = newsize - oldsize;
int rounded_oldsize = oldsize;
+if (oldsize < 0 || newsize < oldsize || newsize >= INT_MAX/2)
+ {
+ log_write(0, LOG_MAIN|LOG_PANIC_DIE,
+ "bad memory extension requested (%d -> %d bytes)",
+ oldsize, newsize);
+ }
+
if (rounded_oldsize % alignment != 0)
rounded_oldsize += alignment - (rounded_oldsize % alignment);
@@ -508,7 +521,16 @@ store_newblock_3(void * block, int newsize, int len,
const char * filename, int linenumber)
{
BOOL release_ok = store_last_get[store_pool] == block;
-uschar * newtext = store_get(newsize);
+uschar * newtext;
+
+if (len < 0 || len > newsize)
+ {
+ log_write(0, LOG_MAIN|LOG_PANIC_DIE,
+ "bad memory extension requested (%d -> %d bytes)",
+ len, newsize);
+ }
+
+newtext = store_get(newsize);
memcpy(newtext, block, len);
if (release_ok) store_release_3(block, filename, linenumber);
@@ -539,6 +561,11 @@ store_malloc_3(int size, const char *filename, int linenumber)
{
void *yield;
+if (size < 0 || size >= INT_MAX/2)
+ log_write(0, LOG_MAIN|LOG_PANIC_DIE,
+ "bad memory allocation requested (%d bytes)",
+ size);
+
if (size < 16) size = 16;
if (!(yield = malloc((size_t)size)))