libstdc++: fix buffer overflow in path::operator+= (PR92853)
commit023a3fb4915841a3eb469b71cf642b5763163e14
authorJonathan Wakely <jwakely@redhat.com>
Mon, 9 Dec 2019 09:58:56 +0000 (9 09:58 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 9 Dec 2019 09:58:56 +0000 (9 09:58 +0000)
treed7e6eb53a9cc6a33f719349821e7e1caeed54a8a
parenta65d584dc1aaaad77af0a8e2ab36a29729d6e056
libstdc++: fix buffer overflow in path::operator+= (PR92853)

When concatenating a path ending in a root-directory onto another path,
we added an empty filename to the end of the path twice, but only
reserved space for one. That meant the second write went past the end of
the allocated buffer.

PR libstdc++/92853
* src/c++17/fs_path.cc (filesystem::path::operator+=(const path&)):
Do not process a trailing directory separator twice.
* testsuite/27_io/filesystem/path/concat/92853.cc: New test.
* testsuite/27_io/filesystem/path/concat/path.cc: Test more cases.

From-SVN: r279110
libstdc++-v3/ChangeLog
libstdc++-v3/src/c++17/fs_path.cc
libstdc++-v3/testsuite/27_io/filesystem/path/concat/92853.cc [copied from libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc with 57% similarity]
libstdc++-v3/testsuite/27_io/filesystem/path/concat/path.cc