diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2025-04-30 17:31:01 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2025-05-06 17:19:26 +0100 |
commit | a067cbcdcc5f599a2b7d607e89674533d23c652d (patch) | |
tree | 1cca68f2853e1bee55b7b2f1a6a1941a9aca2ede /libjava/classpath/java | |
parent | ccf0b93b3ccf67b98fbd5096852c369d2cac7904 (diff) | |
download | gcc-a067cbcdcc5f599a2b7d607e89674533d23c652d.zip gcc-a067cbcdcc5f599a2b7d607e89674533d23c652d.tar.gz gcc-a067cbcdcc5f599a2b7d607e89674533d23c652d.tar.bz2 |
libstdc++: Fix dangling pointer in fs::path::operator+=(*this) [PR120029]
When concatenating a path we reallocate the left operand's storage to
make room for the new components being added. When the two operands are
the same object, or the right operand is one of the components of the
left operand, the reallocation invalidates the pointers that refer
into the right operand's storage.
The solution in this commit is to detect these aliasing cases and just
do the concatenation in terms of the contained string, as that code
already handles the case where the string aliases the path. The standard
specifies the concatenation in terms of the native() string, so all this
change does is disable the optimized implementation of concatenation for
path objects which attempts to avoid re-parsing the path from the
concatenated string.
The potential loss of performance for this case isn't likely to be an
issue, because concatenating a path with itself (or one of its existing
components) probably isn't a common use case.
The Filesystem TS implementation doesn't have the optimized form of
concatenation and always does it in terms of the native string and
reparsing the whole thing, so doesn't have this bug. A test is added to
confirm that anyway (that test has some slightly different results due
to different behaviour for trailing slashes and implicit "." filenames
in the TS spec).
libstdc++-v3/ChangeLog:
PR libstdc++/120029
* src/c++17/fs_path.cc (path::operator+=(const path&)): Handle
parameters that alias the path or one of its components.
* testsuite/27_io/filesystem/path/concat/120029.cc: New test.
* testsuite/experimental/filesystem/path/concat/120029.cc: New
test.
Diffstat (limited to 'libjava/classpath/java')
0 files changed, 0 insertions, 0 deletions