summaryrefslogtreecommitdiff
path: root/src/secmem.c
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2017-06-02 10:34:42 +0900
committerNIIBE Yutaka <gniibe@fsij.org>2017-06-02 10:34:42 +0900
commite0958debe1a7db1bec1283115cdc6a14bf3b43e5 (patch)
tree291bd035e54f94ddf74130b527f275d7df41fa60 /src/secmem.c
parent5a22de904a0a366ae79f03ff1e13a1232a89e26b (diff)
downloadlibgcrypt-e0958debe1a7db1bec1283115cdc6a14bf3b43e5.tar.gz
secmem: Fix SEGV and stat calculation.
* src/secmem (init_pool): Care about the header size. (_gcry_secmem_malloc_internal): Likewise. (_gcry_secmem_malloc_internal): Use mb->size for stats. -- GnuPG-bug-id: 3027 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'src/secmem.c')
-rw-r--r--src/secmem.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/secmem.c b/src/secmem.c
index 8eb66307..86de72d0 100644
--- a/src/secmem.c
+++ b/src/secmem.c
@@ -454,7 +454,7 @@ init_pool (pooldesc_t *pool, size_t n)
/* Initialize first memory block. */
mb = (memblock_t *) pool->mem;
- mb->size = pool->size;
+ mb->size = pool->size - BLOCK_HEAD_SIZE;
mb->flags = 0;
}
@@ -610,7 +610,7 @@ _gcry_secmem_malloc_internal (size_t size, int xhint)
mb = mb_get_new (pool, (memblock_t *) pool->mem, size);
if (mb)
{
- stats_update (pool, size, 0);
+ stats_update (pool, mb->size, 0);
return &mb->aligned.c;
}
@@ -624,7 +624,7 @@ _gcry_secmem_malloc_internal (size_t size, int xhint)
mb = mb_get_new (pool, (memblock_t *) pool->mem, size);
if (mb)
{
- stats_update (pool, size, 0);
+ stats_update (pool, mb->size, 0);
return &mb->aligned.c;
}
}
@@ -641,7 +641,7 @@ _gcry_secmem_malloc_internal (size_t size, int xhint)
return NULL; /* Not enough memory available for a new pool. */
/* Initialize first memory block. */
mb = (memblock_t *) pool->mem;
- mb->size = pool->size;
+ mb->size = pool->size - BLOCK_HEAD_SIZE;
mb->flags = 0;
pool->okay = 1;
@@ -660,7 +660,7 @@ _gcry_secmem_malloc_internal (size_t size, int xhint)
mb = mb_get_new (pool, (memblock_t *) pool->mem, size);
if (mb)
{
- stats_update (pool, size, 0);
+ stats_update (pool, mb->size, 0);
return &mb->aligned.c;
}
}