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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: m(dot)korotkov(at)postgrespro(dot)ru
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [PATCH] dynahash: add memory allocation failure check
Date: 2025-04-23 19:42:53
Message-ID: 1484393.1745437373@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

m(dot)korotkov(at)postgrespro(dot)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_ALLOC_NO_OOM and can return a NULL pointer.

Ugh, that's a stupid bug. Evidently my fault, too (9c911ec06).

> Added the pointer check for avoiding a potential problem.

This doesn't seem like a nice way to fix it. The code right there is
assuming palloc semantics, which was okay before 9c911ec06, but is so
no longer. I think the right thing is to put it back to palloc
semantics, which means not using DynaHashAlloc there, as attached.

regards, tom lane

Attachment Content-Type Size
v2-fix-missing-palloc-check-in-dynahash.patch text/x-diff 623 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrew Dunstan 2025-04-23 19:56:06 Re: Cygwin support
Previous Message Tom Lane 2025-04-23 18:14:34 Re: pgsql: Add function to get memory context stats for processes