Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tjj8B-00CrCE-UL for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Feb 2025 18:12:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tjj88-00A0VG-J0 for pgsql-hackers@arkaria.postgresql.org; Sun, 16 Feb 2025 18:12:36 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tjj88-00A0R0-8H for pgsql-hackers@lists.postgresql.org; Sun, 16 Feb 2025 18:12:36 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tjj85-001CNj-2j for pgsql-hackers@postgresql.org; Sun, 16 Feb 2025 18:12:35 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 51GICIUq626105; Sun, 16 Feb 2025 13:12:18 -0500 From: Tom Lane To: Melanie Plageman cc: Thomas Munro , Masahiko Sawada , Tomas Vondra , Noah Misch , vignesh C , Andres Freund , Pg Hackers , Heikki Linnakangas , Nazir Bilal Yavuz , Robert Haas , "Andrey M. Borodin" Subject: Re: Confine vacuum skip logic to lazy_scan_skip In-reply-to: References: <20240306234733.nd4a636colxkgq2e@liskov> <20240707144944.58.nmisch@google.com> <20240716015226.60.nmisch@google.com> <85696b8e-f1bf-459e-ba97-5608c644c185@vondra.me> <3915749.1739574230@sss.pgh.pa.us> Comments: In-reply-to Thomas Munro message dated "Sat, 15 Feb 2025 14:23:08 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <626103.1739729538.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 16 Feb 2025 13:12:18 -0500 Message-ID: <626104.1739729538@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thomas Munro writes: > Thanks! It's green again. The security team's Coverity instance complained about this patch: *** CID 1642971: Null pointer dereferences (FORWARD_NULL) /srv/coverity/git/pgsql-git/postgresql/src/backend/access/heap/vacuumlazy.= c: 1295 in lazy_scan_heap() 1289 buf =3D read_stream_next_buffer(stream, &per_buffer_data); 1290 = 1291 /* The relation is exhausted. */ 1292 if (!BufferIsValid(buf)) 1293 break; 1294 = >>> CID 1642971: Null pointer dereferences (FORWARD_NULL) >>> Dereferencing null pointer "per_buffer_data". 1295 blk_info =3D *((uint8 *) per_buffer_data); 1296 CheckBufferIsPinnedOnce(buf); 1297 page =3D BufferGetPage(buf); 1298 blkno =3D BufferGetBlockNumber(buf); 1299 = 1300 vacrel->scanned_pages++; Basically, Coverity doesn't understand that a successful call to read_stream_next_buffer must set per_buffer_data here. I don't think there's much chance of teaching it that, so we'll just have to dismiss this item as "intentional, not a bug". However, I do have a suggestion: I think the "per_buffer_data" variable should be declared inside the "while (true)" loop not outside. That way there is no chance of a value being carried across iterations, so that if for some reason read_stream_next_buffer failed to do what we expect and did not set per_buffer_data, we'd be certain to get a null-pointer core dump rather than accessing data from a previous buffer. regards, tom lane