pgsql: Fix SHMEM_ATTACH_iso-8859-1_SIZE when the shmem area doesn't exist - Mailing list pgsql-committers

From Heikki Linnakangas
Subject pgsql: Fix SHMEM_ATTACH_iso-8859-1_SIZE when the shmem area doesn't exist
Date
Msg-id E1x7Ugn-00000000F9A-33Ly@gemulon.postgresql.org
Whole thread
List pgsql-committers
Fix SHMEM_ATTACH_UNKNOWN_SIZE when the shmem area doesn't exist

SHMEM_ATTACH_UNKNOWN_SIZE can be passed as argument to
ShmemRequestStruct() when the caller wants to attach to an existing
shared memory structure whose size it doesn't know.  If the shared
memory structure doesn't exist, the request should fail, but instead,
ProcessShmemRequestsAfterStartup() tried to create the structure with
size = -1.  That led to integer overflow in ShmemAllocRaw() and memory
corruption.

Fix by rejecting requests with SHMEM_ATTACH_UNKNOWN_SIZE when the
structure doesn't exist.  Also add an integer overflow check in
ShmemAllocRaw(), to protect from this kind of confusion or simply too
large requests.  Also document SHMEM_ATTACH_UNKNOWN_SIZE.

Author: Ashutosh Bapat <ashutosh.bapat.oss@gmail.com>
Discussion: https://www.postgresql.org/message-id/CAExHW5u_fTsOAS85kG981Vu6eR1GV-344rup6zYew7xMjEDREw@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/311df1dc0392f06973cf98eac51d63cb007267ce

Modified Files
--------------
doc/src/sgml/xfunc.sgml                            | 10 ++++++++++
src/backend/storage/ipc/shmem.c                    | 22 ++++++++++++++++++++--
.../modules/test_shmem/t/001_late_shmem_alloc.pl   | 17 +++++++++++++++++
src/test/modules/test_shmem/test_shmem.c           | 11 +++++++----
4 files changed, 54 insertions(+), 6 deletions(-)


pgsql-committers by date:

Previous
From: Etsuro Fujita
Date:
Subject: pgsql: postgres_fdw: Fix oversights in fetch_attstats().
Next
From: Álvaro Herrera
Date:
Subject: pgsql: Tighten definition of ON CONFLICT arbiter index equivalence