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

From: Andrey Borodin <x4mmm(at)yandex-team(dot)ru>
To: m(dot)korotkov(at)postgrespro(dot)ru
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] dynahash: add memory allocation failure check
Date: 2025-04-23 09:46:40
Message-ID: BC159F74-1862-4B3A-9D31-29BF408F58A4@yandex-team.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On 23 Apr 2025, at 13:32, m(dot)korotkov(at)postgrespro(dot)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 MemoryContextAllocExtended() with MCXT_ALLOC_NO_OOM and can return a NULL pointer.
> Added the pointer check for avoiding a potential problem.

Yeah, good catch.
And all HTAB->alloc() (which relies on DynaHashAlloc) callers seem to check for NULL result.
It seems there are a lot of cases of MCXT_ALLOC_NO_OOM, perhaps should we check them all?

Best regards, Andrey Borodin.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Antonin Houska 2025-04-23 10:26:12 Re: Conflicting updates of command progress
Previous Message Jelte Fennema-Nio 2025-04-23 09:46:32 Re: What's our minimum supported Python version?