From a9e163047eba9dae6b8c8ed8da5dc3bba8aa2f16 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Wed, 6 Apr 2022 16:30:35 +0900 Subject: [PATCH] Fix shared memory allocation function. pool_shared_memory_segment_get_chunk() which is responsible for shared memory allocation, failed to consider request size alignment. If requeste size is not in MAXALIGN (typically 8) bytes, it could overrun the shared memory area. Probably harmless in the wild but better to fix. --- src/utils/pool_shmem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/pool_shmem.c b/src/utils/pool_shmem.c index 077266169..65597a5dc 100644 --- a/src/utils/pool_shmem.c +++ b/src/utils/pool_shmem.c @@ -5,7 +5,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Portions Copyright (c) 2003-2021, PgPool Global Development Group + * Portions Copyright (c) 2003-2022, PgPool Global Development Group * Portions Copyright (c) 2003-2004, PostgreSQL Global Development Group * * Permission to use, copy, modify, and distribute this software and @@ -78,7 +78,7 @@ pool_shared_memory_segment_get_chunk(size_t size) return NULL; } /* check if we have enough space left in chunk */ - if ((shared_mem_free_pos - (char*)shared_mem_chunk) + size > chunk_size) + if ((shared_mem_free_pos - (char*)shared_mem_chunk) + MAXALIGN(size) > chunk_size) { ereport(ERROR, (errmsg("no space left in shared memory segment"))); -- 2.39.5