From 7ed2e194b4ddd50bd492da421e59033042717ae1 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Wed, 13 Jan 2021 18:49:51 +0900 Subject: [PATCH] Fix error while allocating shared memory. If num_init_children * max_pool is huge, pool_coninfo_size() failed to calculate the size of required shared memory because the data type used for the variable to store shared memory size was int and it overflows for too large shared memory size. To fix this change pool_coninfo_size() to size_t and use appropriate size_t for the variable used within the function. Also fix to use proper format qualifier in pool_shared_memory_create(). --- src/context/pool_process_context.c | 8 ++++---- src/include/context/pool_process_context.h | 4 ++-- src/utils/pool_shmem.c | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/context/pool_process_context.c b/src/context/pool_process_context.c index baa4d7090..56f918d28 100644 --- a/src/context/pool_process_context.c +++ b/src/context/pool_process_context.c @@ -6,7 +6,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2017 PgPool Global Development Group + * Copyright (c) 2003-2021 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -104,10 +104,10 @@ pool_incremnet_local_session_id(void) /* * Return byte size of connection info(ConnectionInfo) on shmem. */ -int +size_t pool_coninfo_size(void) { - int size; + size_t size; size = pool_config->num_init_children * pool_config->max_pool * @@ -115,7 +115,7 @@ pool_coninfo_size(void) sizeof(ConnectionInfo); ereport(DEBUG1, - (errmsg("pool_coninfo_size: num_init_children (%d) * max_pool (%d) * MAX_NUM_BACKENDS (%d) * sizeof(ConnectionInfo) (%zu) = %d bytes requested for shared memory", + (errmsg("pool_coninfo_size: num_init_children (%d) * max_pool (%d) * MAX_NUM_BACKENDS (%d) * sizeof(ConnectionInfo) (%zu) = %zu bytes requested for shared memory", pool_config->num_init_children, pool_config->max_pool, MAX_NUM_BACKENDS, diff --git a/src/include/context/pool_process_context.h b/src/include/context/pool_process_context.h index d57bb0511..646961eb5 100644 --- a/src/include/context/pool_process_context.h +++ b/src/include/context/pool_process_context.h @@ -6,7 +6,7 @@ * pgpool: a language independent connection pool server for PostgreSQL * written by Tatsuo Ishii * - * Copyright (c) 2003-2015 PgPool Global Development Group + * Copyright (c) 2003-2021 PgPool Global Development Group * * Permission to use, copy, modify, and distribute this software and * its documentation for any purpose and without fee is hereby @@ -59,7 +59,7 @@ extern void pool_init_process_context(void); extern POOL_PROCESS_CONTEXT * pool_get_process_context(void); extern ProcessInfo * pool_get_my_process_info(void); extern void pool_incremnet_local_session_id(void); -extern int pool_coninfo_size(void); +extern size_t pool_coninfo_size(void); extern int pool_coninfo_num(void); extern ConnectionInfo * pool_coninfo(int child, int connection_pool, int backend); extern ConnectionInfo * pool_coninfo_pid(int pid, int connection_pool, int backend); diff --git a/src/utils/pool_shmem.c b/src/utils/pool_shmem.c index 787db3f15..c46d9c541 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-2011, PgPool Global Development Group + * Portions Copyright (c) 2003-2021, PgPool Global Development Group * Portions Copyright (c) 2003-2004, PostgreSQL Global Development Group * * Permission to use, copy, modify, and distribute this software and @@ -54,7 +54,7 @@ pool_shared_memory_create(size_t size) if (shmid < 0) ereport(FATAL, - (errmsg("could not create shared memory for request size: %ld", size), + (errmsg("could not create shared memory for request size: %zu", size), errdetail("shared memory creation failed with error \"%m\""))); /* Register on-exit routine to delete the new segment */ -- 2.39.5