Re: [PATCH] dynahash: add memory allocation failure check

2025-04-24 Thread Andrey Borodin
> On 24 Apr 2025, at 19:10, Tom Lane wrote: > > I thought about that but intentionally left it as-is, because that > would force zeroing of the space reserved for the hashtable name too. > That's unnecessary, and since it'd often be odd-sized it might result > in a less efficient fill loop. W

Re: [PATCH] dynahash: add memory allocation failure check

2025-04-24 Thread Tom Lane
Andrey Borodin writes: > While fixing this maybe use MemoryContextAllocZero() instead of subsequent > MemSet()? I thought about that but intentionally left it as-is, because that would force zeroing of the space reserved for the hashtable name too. That's unnecessary, and since it'd often be odd

Re: [PATCH] dynahash: add memory allocation failure check

2025-04-24 Thread Andrey Borodin
> On 24 Apr 2025, at 00:42, Tom Lane wrote: > > - hashp = (HTAB *) DynaHashAlloc(sizeof(HTAB) + strlen(tabname) + 1); > + hashp = (HTAB *) MemoryContextAlloc(CurrentDynaHashCxt, > + sizeof(HTAB) + strlen(tabname) + 1); This seems correct to me. While fixing this maybe use MemoryContextAllocZ

Re: [PATCH] dynahash: add memory allocation failure check

2025-04-23 Thread Tom Lane
m.korot...@postgrespro.ru writes: > I found a case of potential NULL pointer dereference. > In src/backend/utils/hash/dynahash.c in function HTAB *hash_create() the > result of the DynaHashAlloc() is used unsafely. > The function DynaHashAlloc() calls MemoryContextAllocExtended() with > MCXT_ALLO

Re: [PATCH] dynahash: add memory allocation failure check

2025-04-23 Thread m . korotkov
Andrey Borodin wrote 2025-04-23 12:46: It seems there are a lot of cases of MCXT_ALLOC_NO_OOM, perhaps should we check them all? Yep, I think we should. I found this issue with the Svace static analyzer, and it might have missed other issues. Perhaps a more comprehensive investigation is neede

Re: [PATCH] dynahash: add memory allocation failure check

2025-04-23 Thread Aleksander Alekseev
Hi Maksim, > I found a case of potential NULL pointer dereference. > In src/backend/utils/hash/dynahash.c in function HTAB *hash_create() the > result of the DynaHashAlloc() is used unsafely. > The function DynaHashAlloc() calls MemoryContextAllocExtended() with > MCXT_ALLOC_NO_OOM and can return

Re: [PATCH] dynahash: add memory allocation failure check

2025-04-23 Thread Andrey Borodin
> On 23 Apr 2025, at 13:32, m.korot...@postgrespro.ru wrote: > > I found a case of potential NULL pointer dereference. > In src/backend/utils/hash/dynahash.c in function HTAB *hash_create() the > result of the DynaHashAlloc() is used unsafely. > The function DynaHashAlloc() calls MemoryContext