]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: mempool-alloconly unit test improvement: verify that data stack isn't used by...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 21 Feb 2016 17:01:31 +0000 (19:01 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 21 Feb 2016 17:03:17 +0000 (19:03 +0200)
src/lib/test-mempool-alloconly.c

index 4c980de01e43e42973d511c1cbf859572ede7ebc..a4ff0912638f545af77d42c8bb9ebaf3a255f0b1 100644 (file)
@@ -16,15 +16,24 @@ static bool mem_has_bytes(const void *mem, size_t size, uint8_t b)
 
 void test_mempool_alloconly(void)
 {
+#define SENTRY_SIZE 32
+#define SENTRY_CHAR '\xDE'
 #define PMALLOC_MAX_COUNT 128
        pool_t pool;
        unsigned int i, j, k;
        void *mem[PMALLOC_MAX_COUNT + 1];
+       char *sentry;
 
        test_begin("mempool_alloconly");
        for (i = 0; i < 64; i++) {
                for (j = 1; j <= 128; j++) {
                        pool = pool_alloconly_create(MEMPOOL_GROWING"test", i);
+                       /* make sure p_malloc() doesn't overwrite unallocated
+                          data in data stack. parts of the code relies on
+                          this. */
+                       sentry = t_buffer_get(SENTRY_SIZE);
+                       memset(sentry, SENTRY_CHAR, SENTRY_SIZE);
+
                        mem[0] = p_malloc(pool, j);
                        memset(mem[0], j, j);
 
@@ -32,6 +41,8 @@ void test_mempool_alloconly(void)
                                mem[k] = p_malloc(pool, k);
                                memset(mem[k], k, k);
                        }
+                       test_assert(mem_has_bytes(sentry, SENTRY_SIZE, SENTRY_CHAR));
+                       test_assert(t_buffer_get(SENTRY_SIZE) == sentry);
 
                        test_assert(mem_has_bytes(mem[0], j, j));
                        for (k = 1; k <= PMALLOC_MAX_COUNT; k++)