diff mbox series

[committed] libstdc++: Fix out-of-bounds string_view access in filesystem::path [PR 97167]

Message ID 20200922190421.GA684119@redhat.com
State New
Headers show
Series [committed] libstdc++: Fix out-of-bounds string_view access in filesystem::path [PR 97167] | expand

Commit Message

Jonathan Wakely Sept. 22, 2020, 7:04 p.m. UTC
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.

Tested powerpc64le-linux. Committed to trunk.

This needs to be backported to gcc-9 and gcc-10 too.
commit 49ff88bd0d8a36a9e903f01ce05685cfe07dee5d
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Sep 22 20:02:58 2020

    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.
diff mbox series

Patch

diff --git a/libstdc++-v3/src/c++17/fs_path.cc b/libstdc++-v3/src/c++17/fs_path.cc
index cea7aa08601..6e907b1c54d 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();
 }