Fix condition in shm_toc and remove unused function shm_toc_freespace.

From: Zhang Mingli <zmlpostgres(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Fix condition in shm_toc and remove unused function shm_toc_freespace.
Date: 2023-01-12 06:34:01
Message-ID: 1c7954e4-1705-4855-a99d-c77bf426c3e7@Spark
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi, hackers

Some conditions in shm_toc_insert and shm_toc_allocate are bogus, like:

if (toc_bytes + nbytes > total_bytes || toc_bytes + nbytes < toc_bytes)

Remove the condition `toc_bytes + nbytes < toc_bytes` and take a sizeof(shm_entry) into account in shm_toc_allocate though
shm_toc_allocate does that too.

/* Check for memory exhaustion and overflow. */
- if (toc_bytes + nbytes > total_bytes || toc_bytes + nbytes < toc_bytes)
+ if (toc_bytes + sizeof(shm_toc_entry) + nbytes > total_bytes)
{
  SpinLockRelease(&toc->toc_mutex);

shm_toc_freespace is introduced with shm_toc by original commit 6ddd5137b2, but is not used since then, so remove it.

Regards,
Zhang Mingli

Attachment Content-Type Size
v0-0001-Fix-condition-in-shm_toc-and-remove-unused-functi.patch application/octet-stream 2.8 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2023-01-12 06:40:42 Re: Common function for percent placeholder replacement
Previous Message Michael Paquier 2023-01-12 06:30:40 Re: recovery modules