public inbox for [email protected]  
help / color / mirror / Atom feed
dlist_check: add check for nodes pointing to themselves
2+ messages / 2 participants
[nested] [flat]

* dlist_check: add check for nodes pointing to themselves
@ 2026-03-17 12:56 =?utf-8?B?5p2o56OK?= <[email protected]>
  2026-04-08 15:46 ` Re: dlist_check: add check for nodes pointing to themselves [email protected] <[email protected]>
  0 siblings, 1 reply; 2+ messages in thread

From: =?utf-8?B?5p2o56OK?= @ 2026-03-17 12:56 UTC (permalink / raw)
  To: =?utf-8?B?cGdzcWwtaGFja2Vycw==?= <[email protected]>

Hi hackers,

I accidentally called the function dlist_push_head consecutively on the same node, 
inserting it into a doubly linked list, which caused an infinite loop. 
After adding the compile parameter -DILIST_DEBUG, an infinite loop occurred in the dlist_check function, 
revealing that the next pointer of the current node was pointing to itself. 
I am attempting to fix this issue with the following patch.

regards,
Lei Yang

Attachments:

  [application/octet-stream] 0001-dlist_check-add-check-for-nodes-pointing-to-themselv.patch (1.0K, 2-0001-dlist_check-add-check-for-nodes-pointing-to-themselv.patch)
  download | inline diff:
From 016a2c695a55f32a9df0e77ee9142c86c9a8f70d Mon Sep 17 00:00:00 2001
From: Lei Yang <[email protected]>
Date: Tue, 17 Mar 2026 20:51:28 +0800
Subject: [PATCH] dlist_check: add check for nodes pointing to themselves

---
 src/backend/lib/ilist.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/backend/lib/ilist.c b/src/backend/lib/ilist.c
index d238858e24f..27dac796fd2 100644
--- a/src/backend/lib/ilist.c
+++ b/src/backend/lib/ilist.c
@@ -91,7 +91,8 @@ dlist_check(const dlist_head *head)
 			cur->next == NULL ||
 			cur->prev == NULL ||
 			cur->prev->next != cur ||
-			cur->next->prev != cur)
+			cur->next->prev != cur ||
+			cur->next == cur)
 			elog(ERROR, "doubly linked list is corrupted");
 	}
 
@@ -102,7 +103,8 @@ dlist_check(const dlist_head *head)
 			cur->next == NULL ||
 			cur->prev == NULL ||
 			cur->prev->next != cur ||
-			cur->next->prev != cur)
+			cur->next->prev != cur ||
+			cur->prev == cur)
 			elog(ERROR, "doubly linked list is corrupted");
 	}
 }
-- 
2.34.1



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: dlist_check: add check for nodes pointing to themselves
  2026-03-17 12:56 dlist_check: add check for nodes pointing to themselves =?utf-8?B?5p2o56OK?= <[email protected]>
@ 2026-04-08 15:46 ` [email protected] <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: [email protected] @ 2026-04-08 15:46 UTC (permalink / raw)
  To: yanglei <[email protected]>; +Cc: pgsql-hackers <[email protected]>

Currently, postgresql will enter an infinite loop when calling dlist_push_head the second time. 
After applying this patch, it will report ERROR: doubly linked list is corrupted.

test case:
./configure --enable-debug CFLAGS='-O0 -DILIST_DEBUG' --enable-cassert

PG_FUNCTION_INFO_V1(test_dlist);
Datum
test_dlist(PG_FUNCTION_ARGS)
{
dlist_head head;
dlist_node *n;

n = palloc0(sizeof(dlist_node));
dlist_init(&head);
dlist_push_head(&head, n);
dlist_push_head(&head, n);

PG_RETURN_NULL();
}





regards,
Lei Yang
 
From: 杨磊
Date: 2026-03-17 20:56
To: pgsql-hackers
Subject: dlist_check: add check for nodes pointing to themselves
Hi hackers,
 
I accidentally called the function dlist_push_head consecutively on the same node, 
inserting it into a doubly linked list, which caused an infinite loop. 
After adding the compile parameter -DILIST_DEBUG, an infinite loop occurred in the dlist_check function, 
revealing that the next pointer of the current node was pointing to itself. 
I am attempting to fix this issue with the following patch.
 
regards,
Lei Yang


^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-04-08 15:46 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-03-17 12:56 dlist_check: add check for nodes pointing to themselves =?utf-8?B?5p2o56OK?= <[email protected]>
2026-04-08 15:46 ` [email protected] <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox