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 1lEQk3-0006OW-Eh for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Feb 2021 06:00:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lEQk1-0008Lw-Q3 for pgsql-bugs@arkaria.postgresql.org; Tue, 23 Feb 2021 06:00:13 +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 1lEQk1-0008Lj-HP for pgsql-bugs@lists.postgresql.org; Tue, 23 Feb 2021 06:00:13 +0000 Received: from mail-lf1-x12d.google.com ([2a00:1450:4864:20::12d]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lEQjv-0000tW-A7 for pgsql-bugs@lists.postgresql.org; Tue, 23 Feb 2021 06:00:12 +0000 Received: by mail-lf1-x12d.google.com with SMTP id m22so9478752lfg.5 for ; Mon, 22 Feb 2021 22:00:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=fMxgopwzXc2id3lOi/G/3Ot5voPUFFro3y8HKSMNygQ=; b=D2lkpTgbFQoYikGNTmWA7mBtAvVzbk0H9zVf5qfvQFhrbry5Ay5IKjvlWop/bdYAWd oYG0uiM2wGhnBVWik9q0iZnLGSse//duKZrjmgxlJ4hfnhAS6OaZVUWi0sKZWfj2L/I0 jFPjLLaV2ST2G1gmuh2Wz9+ud8Pu0EdMvPKei5N7eDh0WQQECUItOlq1tVmBB/XRHbkj o0WggmjHQjX3oOqyhFevkjQ5k24ILqMWHXvKpdciSwt7f2HjtbE9/LH4TlVVfJ1l0uEC ca2hNau/stgRyqprBgC9JzZ9q+CERWPYl/VI0pNQFiHWxmolHTdmQJMHmjSJrswNPhDv 471Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=fMxgopwzXc2id3lOi/G/3Ot5voPUFFro3y8HKSMNygQ=; b=YeAQhgFwVeMHw0hJdcQ0h4P078NR1mSg8NfIhckv55/Zw2ksxE7DmGRE/Bnpq/ZpXW g+iaeKCUDzaH0kBHDuxMUduEy5jQhLBbKhBvfl4oXJxQq91eEGMXWdAEM6njp7wiWxTb Jv42e8ECXrfIA3Uiz+EU+SKHG3vBfV8j7HOcKYGqEymZW1gFokMF44nr2qB2WlpiexYk 2s69PbUKzur3AXh16hmQ3UhN221GrBOm4cFUvZ2Twjr5vXDEIT0Z86/okdiQSWZixjs8 CAMlPRjF9n07iSjEqOIbY8m7IZV792GdcmEiFTDrg4g5c2/yMrYimIiakseo0PYkYrFk UfUw== X-Gm-Message-State: AOAM532pQdKJ8ABB/3Ct8SYwvOywgCTx0SatGK/138x0rsPgFximxdvN BaZs31Gevm3AIVZG4zINZCxKCvdaZsU= X-Google-Smtp-Source: ABdhPJzpVaCehvSMQz5WzAn51CSiXYyKKu/3aokBvMGq76DGEPpLJ/vPRRlvVeG86aG//ndHh7WCTA== X-Received: by 2002:a19:6f4b:: with SMTP id n11mr7754028lfk.506.1614060003045; Mon, 22 Feb 2021 22:00:03 -0800 (PST) Received: from [1.0.0.7] ([178.155.6.75]) by smtp.gmail.com with ESMTPSA id e18sm36628ljl.92.2021.02.22.22.00.02 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 22 Feb 2021 22:00:02 -0800 (PST) Subject: Re: BUG #16801: Invalid memory access on WITH RECURSIVE with nested WITHs To: Michael Paquier , pgsql-bugs@lists.postgresql.org References: <16801-393c7922143eaa4d@postgresql.org> From: Alexander Lakhin Message-ID: Date: Tue, 23 Feb 2021 09:00:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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