Add an assert to the length of shared hashtable name
Started by Xiaoran Wangover 3 years ago1 messages
The max size for the 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 the caller uses a
longer hash table name, it doesn't report any error, instead it just
uses the first SHMEM_INDEX_KEYSIZE chars as the hash table name.
When some hash tables' names have the same prefix which is longer than
(SHMEM_INDEX_KEYSIZE - 1), issues will come: those hash tables actually
are created as the same hash table whose name is the prefix. So add the
assert to prevent it.
Attachments:
fix_shmem_hash_table_name_length.patchapplication/octet-stream; name=fix_shmem_hash_table_name_length.patchDownload
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);