You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Source build: ign-common3 and ign-common4 branches affected
Description
The sanitizeSlashes lambda inside of ign::common::joinPaths (src/Filesystem.cc) attempts to remove duplicate occurrences of the path separator character at the beginning and end of a string. It does so by iterating over the string's characters forward from the beginning, and then backward from the end, until it reaches a character that is not a path separator variable, and then deletes characters leading up to the last path separator detected.
Under certain conditions, such as when the input string only contains one or more path separator variables, the loop iterating backwards from the end of the string will get to position 0, and then on the next iteration wrap the loop counter and attempt to access an element of the string way out of the string's bounds. I believe in the forward case, the loop iterating forward hits the null terminator at the end of the string, and will not continue to access any of the string out of bounds.
When compiled with -D_GLIBCXX_ASSERTIONS, an assertion is added to the C++ standard library for out-of-bounds accesses with methods like operator[](). The FilesystemTest.basename unit test triggers one of these assertions in the UNIT_Filesystem_TEST binary. When triggered, the binary aborts and the suite fails.
Expected behavior: Tests build and run when -D_GLIBCXX_ASSERTIONS is set
Actual behavior: Test aborts due to out-of-bounds access
Changing the for loop condition to index < result.length() && result[index] == replacement in the for loop would break of the loop when wrap-around occurs, before attempting to access the out-of-bounds index.
Environment
ign-common3
andign-common4
branches affectedDescription
The
sanitizeSlashes
lambda inside ofign::common::joinPaths
(src/Filesystem.cc
) attempts to remove duplicate occurrences of the path separator character at the beginning and end of a string. It does so by iterating over the string's characters forward from the beginning, and then backward from the end, until it reaches a character that is not a path separator variable, and then deletes characters leading up to the last path separator detected.Under certain conditions, such as when the input string only contains one or more path separator variables, the loop iterating backwards from the end of the string will get to position 0, and then on the next iteration wrap the loop counter and attempt to access an element of the string way out of the string's bounds. I believe in the forward case, the loop iterating forward hits the null terminator at the end of the string, and will not continue to access any of the string out of bounds.
When compiled with
-D_GLIBCXX_ASSERTIONS
, an assertion is added to the C++ standard library for out-of-bounds accesses with methods likeoperator[]()
. TheFilesystemTest.basename
unit test triggers one of these assertions in theUNIT_Filesystem_TEST
binary. When triggered, the binary aborts and the suite fails.-D_GLIBCXX_ASSERTIONS
is setSteps to reproduce
git checkout ign-common4
CXXFLAGS=-D_GLIBCXX_ASSERTIONS cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug
make -C build UNIT_Filesystem_TEST
./build/bin/UNIT_Filesystem_TEST
gdb -ex run ./build/bin/UNIT_Filesystem_TEST
Output
Program output:
Backtrace (Error can be seen in frame 6,
index
value)The text was updated successfully, but these errors were encountered: