Re: [PATCH v1] Reject zero resource kinds in test_resowner_many()

From: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>
To: Sho Ito <i(dot)sho(dot)0628(at)gmail(dot)com>, Grigorev Jurij <ju(dot)grigorev(at)ftdata(dot)ru>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, "heikki(dot)linnakangas(at)enterprisedb(dot)com" <heikki(dot)linnakangas(at)enterprisedb(dot)com>
Subject: Re: [PATCH v1] Reject zero resource kinds in test_resowner_many()
Date: 2026-10-09 21:29:27
Message-ID: 1e072946-325a-4076-a41a-7eb19356ed04@iki.fi
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 09/10/2026 07:48, Sho Ito wrote:
> On Fri, Oct 9, 2026 at 12:32 AM Grigorev Jurij <ju(dot)grigorev(at)ftdata(dot)ru
> <mailto:ju(dot)grigorev(at)ftdata(dot)ru>> wrote:
>> While running Clang Static Analyzer through CodeChecker over PostgreSQL
>> 18.6, we found a possible division by zero in
>> RememberManyTestResources():
>>
>>     kind_idx = (kind_idx + 1) % nkinds;
>>
>> The SQL entry point rejects negative values of nkinds but accepts zero.
>> If there are resources to remember, the helper then accesses kinds[0]
>> even though the array contains no resource kinds, and can eventually
>> reach the modulo operation.

Meh, ok. This is just test code, but sure, if we bother to check it at
all, let's get it right.

>> I would also appreciate opinions on whether this test-only fix is worth
>> back-patching to PostgreSQL 17 and 18.  I can prepare separate
>> back-branch patches if needed.

Nah, thanks but not worth back-patching.

> I reviewed v1 on master with assertions enabled. The test_resowner
> regression test passes. Both zero-kind remember cases abort without the
> patch and return the expected SQL error with it. I found no blocking
> issues with this test-code fix.
Thanks, I've pushed the code change. Thanks for the tests, they were
nice to demonstrate the problem, but I didn't include them as these are
just test functions anyway. We don't need tests for tests.

- Heikki

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2026-10-09 22:21:38 Re: Fix a wal_debug crash with the new shmem allocation API
Previous Message Matthias van de Meent 2026-10-09 21:22:38 Re: POC: Unlocked path for GetSnapshotDataReuse