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.96) (envelope-from ) id 1wAV8g-0002A0-2j for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 15:48:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wAV7e-000Rjf-2h for pgsql-hackers@arkaria.postgresql.org; Wed, 08 Apr 2026 15:47:19 +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.96) (envelope-from ) id 1wAV7d-000RjV-2u for pgsql-hackers@lists.postgresql.org; Wed, 08 Apr 2026 15:47:19 +0000 Received: from m16.mail.126.com ([117.135.210.7]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wAV7W-000000001jT-09cD for pgsql-hackers@lists.postgresql.org; Wed, 08 Apr 2026 15:47:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Date:From:To:Subject:Mime-Version:Message-ID: Content-Type; bh=WmBmviDceMyDH/uEIHdsF3omDash4fCu6Ig9jMTgd0A=; b=LgOe5gizfpKTQsRtIMeAaFOdOlbYUtfd/p0Uu1bHzX9d0HB/p5zDssJ16l3TMk zWPGUpnd5neW9Rb2PXhWP8o1PHAHIG95TKsT/JnJ/Ws+Ea3ZJwVDWab4a+nZ9hls Kofbw+5gMIeR73eGiAUZDCNeJTlrnvY0M5Om48cnn4PZA= Received: from DESKTOP-JPDUFHL (unknown []) by gzga-smtp-mtada-g0-4 (Coremail) with SMTP id _____wD31+BzeNZp374aBQ--.14483S2; Wed, 08 Apr 2026 23:46:59 +0800 (CST) Date: Wed, 8 Apr 2026 23:46:59 +0800 From: "ylshiyu@126.com" To: yanglei Cc: pgsql-hackers Subject: Re: dlist_check: add check for nodes pointing to themselves References: X-Priority: 3 X-GUID: 06AC62E1-0EF4-4C7F-94D7-48F447609E41 X-Has-Attach: no X-Mailer: Foxmail 7.2.25.331[cn] Mime-Version: 1.0 Message-ID: <202604082346585927708@126.com> Content-Type: multipart/alternative; boundary="----=_001_NextPart863246785062_=----" X-CM-TRANSID: _____wD31+BzeNZp374aBQ--.14483S2 X-Coremail-Antispam: 1Uf129KBjvdXoW7JrWxWr47Kw1DWrW3Xr4fZrb_yoWkGrg_ur yft34qgw1UJrs0kF4DCF4rWr1agrWrtr1kJ34xWry7AryrCr4kuF9Fk3sF9348W3yaqrsI vrs3X345Cr1xujkaLaAFLSUrUUUUjb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUvcSsGvfC2KfnxnUUI43ZEXa7sRXiSL7UUUUU== X-Originating-IP: [117.147.90.155] X-CM-SenderInfo: x1ovxxl1x6ij2wof0z/xtbBohNKJmnWeHMBGgAA3y List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. ------=_001_NextPart863246785062_=---- Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: base64 Q3VycmVudGx5LCBwb3N0Z3Jlc3FsIHdpbGwgZW50ZXIgYW4gaW5maW5pdGUgbG9vcCB3aGVuIGNh bGxpbmcgZGxpc3RfcHVzaF9oZWFkIHRoZSBzZWNvbmQgdGltZS4gDQpBZnRlciBhcHBseWluZyB0 aGlzIHBhdGNoLCBpdCB3aWxsIHJlcG9ydCBFUlJPUjogZG91Ymx5IGxpbmtlZCBsaXN0IGlzIGNv cnJ1cHRlZC4NCg0KdGVzdCBjYXNlOg0KLi9jb25maWd1cmUgLS1lbmFibGUtZGVidWcgQ0ZMQUdT PSctTzAgLURJTElTVF9ERUJVRycgLS1lbmFibGUtY2Fzc2V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gaXNzdWUgd2l0aCB0aGUgZm9sbG93aW5nIHBh dGNoLg0KIA0KcmVnYXJkcywNCkxlaSBZYW5nDQo= ------=_001_NextPart863246785062_=---- Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable = =0A
Curren= tly, postgresql will enter an infinite loop when calling dlist_push_head t= he second time. 
After applying this patch,&nbs= p;it will report ERROR: dou= bly linked list is corrupted.

test case:
./configure --enable-debug CFLAGS=3D'-O0 -DILIST_DEBUG' --enable-c= assert

PG_FUNCTION_INFO_V1(test_dlist);
Datum
test_dlist(PG_FUNCTION_ARGS)
{
<= span style=3D"white-space:pre"> dlist_head head;
dlist_node *n;

n =3D palloc0(sizeof(dlist_node));
dlist_init(&head);
dlist_push_head(&head,= n);
dlist_push_head(&am= p;head, n);

PG_RETURN_NULL();
}


= =0A


=0A
regards,
Lei Yang
=0A
 
=
Date: 2026-03-17 2= 0:56
Subject: dlist_check: a= dd check for nodes pointing to themselves
Hi ha= ckers,
=0A
 
=0A
I accidentally called the function= dlist_push_head consecutively on the same node,
=0A
inserting i= t into a doubly linked list, which caused an infinite loop.
=0A
= After adding the compile parameter -DILIST_DEBUG, an infinite loop occurre= d in the dlist_check function,
=0A
revealing that the next point= er of the current node was pointing to itself.
=0A
I am attempti= ng to fix this issue with the following patch.
=0A
 
= =0A
regards,
=0A
Lei Yang
=0A
=0A ------=_001_NextPart863246785062_=------