Fix shared memory allocation function.
authorTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 6 Apr 2022 07:30:35 +0000 (16:30 +0900)
committerTatsuo Ishii <ishii@sraoss.co.jp>
Wed, 6 Apr 2022 07:30:35 +0000 (16:30 +0900)
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

index 077266169976232f0ffa7a959938f8df31e578ae..65597a5dcc0f5e6a0a430eff1169f9181819125d 100644 (file)
@@ -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")));