Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pFtMO-00046I-PJ for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jan 2023 08:54:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pFtMN-000684-P9 for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Jan 2023 08:54:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pFtMN-00067v-EZ for pgsql-hackers@lists.postgresql.org; Thu, 12 Jan 2023 08:54:55 +0000 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pFtMK-0006ty-LZ for pgsql-hackers@lists.postgresql.org; Thu, 12 Jan 2023 08:54:54 +0000 Received: by mail-pl1-x62a.google.com with SMTP id p24so19544018plw.11 for ; Thu, 12 Jan 2023 00:54:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=A0EbvMmOpzZy9eAjZ3ExdRui+LqaBOseY7BLs7jdBHY=; b=PeTsrwBHNjvmparKfD29mahMDVTZiYp8ZSas9hS3oR8NQ3dMh8MuP9qjhY3cxwtbzd CLLdOEIu7jaw8rnA1HrPf7S5R17D46/zN0ZbqAWPt6nVgIZR3OMBHfNBqQn1mrJ6Zuf7 ZwVHnJfdlrVtq3Kv2Nz+thbecwGTR0IZjBZCqiHdsGUTb4tyuxn4cT23GmQlSAUHwod8 hILXEwFeqJwyH7do7oz6EDYnXQyoaem1HQu9SLd9IKEc+maZjWaJtskCqDw/flBVkJqz XCadc9ksXDYv1sP2AapqeRVMrlQsf8f8PAoW4o3Gkxt+lImH/qkxKPnVZGr+U9qQl3xJ gILw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=A0EbvMmOpzZy9eAjZ3ExdRui+LqaBOseY7BLs7jdBHY=; b=UyKAkE4ew94HGgnqHxnPTllqFHZw+qpHSs3IKH8DjVQ2ip16Py0yMqanDxCbr5pRXu eEpTES8EF7lT7dSlT/IFERHkjvbJaqZF9w0/bKKjphv2zrNDsi8a3i6c3/KM7s5159qc wPk4pdaGebc1sjmpLbuYhS2Dkwd8mzfB/AKNQm5cqya4TaZOapfAXkoC9wtyhuNq/1+v b0bhaUMS/QEtyq/N+EGvVpzdho6wjRd5VCNiDH2z6WjoP3UnHwXiigDsHh+XSW09/0z7 jJI4qKqRkyfHYr/1EZGPXZf0y3ORoAF8ipGC7cum2OamHsTo0h4pI9cnHomFnDzsAbcu uP6g== X-Gm-Message-State: AFqh2kqH6fdGyRRwivbmweHkMF+caA28BHyaWfy9+kcA4Qm6dhgKuwB6 k0LZLFU3kLRxJS4JljfWRl/bxRVwH8DjpXuRD/4= X-Google-Smtp-Source: AMrXdXshgw+iFUW9jbRvBuqxECFtwXyU5/0DDWW7iySxASO7tdAWBI05LQfoXv0IdAUCeC0nYvi9P8OWCAz38OVTelc= X-Received: by 2002:a17:90a:c70e:b0:228:e263:f86f with SMTP id o14-20020a17090ac70e00b00228e263f86fmr677719pjt.41.1673513691318; Thu, 12 Jan 2023 00:54:51 -0800 (PST) MIME-Version: 1.0 References: <1c7954e4-1705-4855-a99d-c77bf426c3e7@Spark> <70ce9710-e9ed-4a25-a327-88de830b8cf6@Spark> In-Reply-To: <70ce9710-e9ed-4a25-a327-88de830b8cf6@Spark> From: Richard Guo Date: Thu, 12 Jan 2023 16:54:40 +0800 Message-ID: Subject: Re: Fix condition in shm_toc and remove unused function shm_toc_freespace. To: Zhang Mingli Cc: PostgreSQL Hackers Content-Type: multipart/alternative; boundary="000000000000190dbe05f20d459c" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000190dbe05f20d459c Content-Type: text/plain; charset="UTF-8" On Thu, Jan 12, 2023 at 2:50 PM Zhang Mingli wrote: > On Jan 12, 2023, 14:34 +0800, Zhang Mingli , wrote: > > 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. > > shm_toc_insert does that too, and we can report error earlier. > I don't think we should consider sizeof(shm_toc_entry) in the 'if' condition in shm_toc_allocate, as this function is not in charge of allocating a new TOC entry. That's what shm_toc_insert does. Other parts of this patch look good to me. Thanks Richard --000000000000190dbe05f20d459c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

On Thu, Jan 12, 2023 at 2:50 PM Zhang Min= gli <zmlpostgres@gmail.com&= gt; wrote:
On Jan 12, 2023, 14:34 +0800, Zhang Mingli <zmlpostgres@gmail.com>, wrote:
<= blockquote style=3D"border-left:thin solid rgb(26,188,156);margin:5px;paddi= ng-left:10px"> 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=C2=A0
shm_toc_allocate does that too.
=C2=A0=C2=A0shm_toc_insert does that too, and=C2=A0=C2=A0= we can report error earlier.
=C2=A0
I don't think we should consider sizeof(shm_toc_entry) in the = 9;if'
condition in shm_toc_allocate, as this function is not in char= ge of
allocating a new TOC entry.=C2=A0 That's what shm_toc_insert d= oes.

Other parts of this patch look good to me.

Thanks
Ric= hard
--000000000000190dbe05f20d459c--