public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r9-8932] libstdc++: Fix out-of-bounds string_view access in filesystem::path [PR 97167] Date: Tue, 22 Sep 2020 19:59:55 +0000 (GMT) [thread overview] Message-ID: <20200922195955.02977385780B@sourceware.org> (raw) https://gcc.gnu.org/g:e7285587186bac5692171d7493e29e16c729281d commit r9-8932-ge7285587186bac5692171d7493e29e16c729281d Author: Jonathan Wakely <jwakely@redhat.com> 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 a6be0e03a78..b44fae03da0 100644 --- a/libstdc++-v3/src/c++17/fs_path.cc +++ b/libstdc++-v3/src/c++17/fs_path.cc @@ -74,7 +74,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 db80087ba6c..9249cf682ef 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(); }
reply other threads:[~2020-09-22 19:59 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20200922195955.02977385780B@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).