From 67bdc0edb927dfc45f169c452eaa72a8a2f5f687 Mon Sep 17 00:00:00 2001 From: Xiaoran Wang Date: Mon, 26 Sep 2022 12:56:33 +0800 Subject: [PATCH] Adding an assertion to report too long hash table name The max size for shared memory hash table name is SHMEM_INDEX_KEYSIZE - 1 (shared hash table name is stored and indexed by ShmemIndex hash table, the key size of it is SHMEM_INDEX_KEYSIZE), but when a caller uses a longer hash table name, it doesn't report any error, instead it just uses the first SHMEM_INDEX_KEYSIZE -1 chars as the hash table name. When some hash tables' names have the same prefix which is longer than (SHMEM_INDEX_KEYSIZE - 1), and they have the same size, then those hash tables will be created as the same hash table. So add the assertion to prevent it. --- src/backend/storage/ipc/shmem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/storage/ipc/shmem.c b/src/backend/storage/ipc/shmem.c index c1279960cd..c32e4581f7 100644 --- a/src/backend/storage/ipc/shmem.c +++ b/src/backend/storage/ipc/shmem.c @@ -433,6 +433,7 @@ ShmemInitStruct(const char *name, Size size, bool *foundPtr) return structPtr; } + Assert(strlen(name) < SHMEM_INDEX_KEYSIZE); /* look it up in the shmem index */ result = (ShmemIndexEnt *) hash_search(ShmemIndex, name, HASH_ENTER_NULL, foundPtr); -- 2.32.1 (Apple Git-133)