Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs

From: Alexander Lakhin <exclusion(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs
Date: 2021-02-23 06:00:00
Message-ID: eb358b3f-8272-d0a9-6645-983e7ad2bec4@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello Michael,
03.01.2021 08:15, Michael Paquier wrote:
> On Sat, Jan 02, 2021 at 03:00:00PM +0000, PG Bug reporting form wrote:
>> valgrind detects an invalid read:
>> ==00:00:00:04.145 217144== Invalid read of size 8
>> ==00:00:00:04.145 217144== at 0x302CB7: makeDependencyGraphWalker
>> (parse_cte.c:549)
>> ==00:00:00:04.145 217144== by 0x302EA1: makeDependencyGraph
>> (parse_cte.c:439)
>> ==00:00:00:04.145 217144== by 0x304557: transformWithClause
>> (parse_cte.c:176)
>>
>> The first bad commit is 1cff1b95.
> The same kind of list manipulation is done in two places in
> parse_cte.c, and there are extra ones in split_pathtarget_walker(). I
> cannot reproduce that here, and I have just tried with different
> optimization levels on HEAD and REL_13_STABLE. Are you using specific
> options for valgrind?
I've found out that the list implementation doesn't support the
following usage pattern:
List *testList = NIL;
ListCell *testCell;

testList = lcons(NIL, testList);
testCell = list_head(testList);
...
testList = lcons(NIL, testList);

elog(INFO, "lfirst(testCell): %p", lfirst(testCell)); // prints
0x7f7f7f7f7f7f7f7f when compiled with -DUSE_VALGRIND

(Such list manipulation is happening in that makeDependencyGraphWalker
call.)

Best regards,
Alexander

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Thomas Trenz 2021-02-23 08:11:20 Re: BUG #16874: Postgres Server crashes at commit
Previous Message David Rowley 2021-02-23 05:28:18 Re: BUG #16887: Group by is faster than distinct