From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6E6233858408; Mon, 4 Oct 2021 13:22:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E6233858408 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/102592] [11/12 Regression] heap-use-after-free when constructing std::filesystem::path from iterator pair Date: Mon, 04 Oct 2021 13:22:08 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 11.2.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: short_desc everconfirmed assigned_to keywords cf_reconfirmed_on cf_known_to_work bug_status cf_known_to_fail Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2021 13:22:08 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102592 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|heap-use-after-free when |[11/12 Regression] |constructing |heap-use-after-free when |std::filesystem::path from |constructing |iterator pair |std::filesystem::path from | |iterator pair Ever confirmed|0 |1 Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu= .org Keywords| |wrong-code Last reconfirmed| |2021-10-04 Known to work| |10.3.1 Status|UNCONFIRMED |ASSIGNED Known to fail| |11.2.1, 12.0 --- Comment #1 from Jonathan Wakely --- The problem is the last line of this function: template static auto _S_convert(const _Tp& __str) { if constexpr (is_same_v<_Tp, string_type>) return __str; else if constexpr (is_same_v<_Tp, basic_string_view>) return __str; else if constexpr (is_same_v) return basic_string_view(__str.data(), __str.size()); else return _S_convert(__str.data(), __str.data() + __str.size()); } That returns a basic_string_view referring to the contents of __st= r, but that is an rvalue basic_string that goes out of scope before t= he result is used.=