Re: [PATCH v1] Reject zero resource kinds in test_resowner_many() - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: [PATCH v1] Reject zero resource kinds in test_resowner_many()
Date
Msg-id 1e072946-325a-4076-a41a-7eb19356ed04@iki.fi
Whole thread
In response to Re: [PATCH v1] Reject zero resource kinds in test_resowner_many()  (Sho Ito <i.sho.0628@gmail.com>)
List pgsql-hackers
On 09/10/2026 07:48, Sho Ito wrote:
> On Fri, Oct 9, 2026 at 12:32 AM Grigorev Jurij <ju.grigorev@ftdata.ru 
> <mailto:ju.grigorev@ftdata.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




pgsql-hackers by date:

Previous
From: Matthias van de Meent
Date:
Subject: Re: POC: Unlocked path for GetSnapshotDataReuse
Next
From: Heikki Linnakangas
Date:
Subject: Re: Fix a wal_debug crash with the new shmem allocation API