From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 76F9D3894C2A; Tue, 22 Sep 2020 19:34:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76F9D3894C2A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600803283; bh=KTpoX1boVdmsIArTAOuIErg+vptQt/3vKRsoLXR7mwI=; h=From:To:Subject:Date:From; b=YVorC9Ar9Ya08Qmx1nos54PmvmL7KGmwIIxdrFKDLtQ/mYFvLpDquvqY6vKlUkVx6 nxFM/EymmBiokPRqklgW8AjMxgZ0X2ucDXDrqUBRTYUWnoow4EXqDoJjS0s+t2KXXH CJxPr1HWfhb2jqzt690br2DhF5ca0cyeWziBqW4Y= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-8789] libstdc++: Fix out-of-bounds string_view access in filesystem::path [PR 97167] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 283b97965ffbb78323e9b4e962eaf8e2c338c7c5 X-Git-Newrev: ebf259b243069e77dc7199072304b455e8fcb865 Message-Id: <20200922193443.76F9D3894C2A@sourceware.org> Date: Tue, 22 Sep 2020 19:34:43 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 22 Sep 2020 19:34:43 -0000 https://gcc.gnu.org/g:ebf259b243069e77dc7199072304b455e8fcb865 commit r10-8789-gebf259b243069e77dc7199072304b455e8fcb865 Author: Jonathan Wakely Date: Tue Sep 22 20:02:58 2020 +0100 libstdc++: Fix out-of-bounds string_view access in filesystem::path [PR 97167] libstdc++-v3/ChangeLog: PR libstdc++/97167 * src/c++17/fs_path.cc (path::_Parser::root_path()): Check for empty string before inspecting the first character. * testsuite/27_io/filesystem/path/append/source.cc: Append empty string_view to path. (cherry picked from commit 49ff88bd0d8a36a9e903f01ce05685cfe07dee5d) Diff: --- libstdc++-v3/src/c++17/fs_path.cc | 2 +- libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/src/c++17/fs_path.cc b/libstdc++-v3/src/c++17/fs_path.cc index 5ff17741f81..edfb91fc6c5 100644 --- a/libstdc++-v3/src/c++17/fs_path.cc +++ b/libstdc++-v3/src/c++17/fs_path.cc @@ -81,7 +81,7 @@ struct path::_Parser const size_t len = input.size(); // look for root name or root directory - if (is_dir_sep(input[0])) + if (len && is_dir_sep(input[0])) { #if SLASHSLASH_IS_ROOTNAME // look for root name, such as "//foo" diff --git a/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc b/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc index 2fceee9b774..dc7331945fe 100644 --- a/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc +++ b/libstdc++-v3/testsuite/27_io/filesystem/path/append/source.cc @@ -161,6 +161,15 @@ test06() test(p2, s.c_str()); } +void +test07() +{ + path p, p0; + std::string_view s; + p /= s; // PR libstdc++/97167 + compare_paths(p, p0); +} + int main() { @@ -170,4 +179,5 @@ main() test04(); test05(); test06(); + test07(); }