-
Notifications
You must be signed in to change notification settings - Fork 24
prevent symlink loop recursion in directory traversal #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jmestwa-coder
wants to merge
1
commit into
bazel-contrib:main
Choose a base branch
from
jmestwa-coder:replay-fix-symlink-loop-traversal
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+63
−11
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,8 +16,11 @@ | |
|
|
||
| #include <sys/stat.h> | ||
| #include <sys/types.h> | ||
| #include <unistd.h> | ||
|
|
||
| #include <cerrno> | ||
| #include <cstdlib> | ||
| #include <cstring> | ||
| #include <functional> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
@@ -113,6 +116,31 @@ TEST(YieldFilesTest, YieldsHiddenFilesAndDirs) { | |
| EXPECT_THAT(collected_paths, testing::SizeIs(2)); | ||
| } | ||
|
|
||
| TEST(YieldFilesTest, DoesNotRecurseThroughSymlinkLoop) { | ||
| const std::string root_dir = | ||
| absl::StrCat(getenv("TEST_TMPDIR"), "/symlink-loop-root"); | ||
| ASSERT_EQ(mkdir(root_dir.c_str(), 0755), 0); | ||
| const std::string dir_a = absl::StrCat(root_dir, "/dirA"); | ||
| ASSERT_EQ(mkdir(dir_a.c_str(), 0755), 0); | ||
| const std::string dir_b = absl::StrCat(root_dir, "/dirB"); | ||
| ASSERT_EQ(mkdir(dir_b.c_str(), 0755), 0); | ||
|
|
||
| const std::string link_to_b = absl::StrCat(dir_a, "/toB"); | ||
| if (symlink(dir_b.c_str(), link_to_b.c_str()) != 0) { | ||
| GTEST_SKIP() << "symlink unsupported in this environment: " | ||
| << std::strerror(errno); | ||
| } | ||
| const std::string link_to_a = absl::StrCat(dir_b, "/toA"); | ||
| ASSERT_EQ(symlink(dir_a.c_str(), link_to_a.c_str()), 0); | ||
|
|
||
| std::vector<std::string> collected_paths; | ||
| const absl::Status status = | ||
| YieldFiles(root_dir, CollectPathsCallback(&collected_paths)); | ||
| EXPECT_TRUE(status.ok()); | ||
| EXPECT_GT(collected_paths.size(), 0); | ||
| EXPECT_LE(collected_paths.size(), 6); | ||
|
Comment on lines
+140
to
+141
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The tests would need one or two normal files after adjusting the callback handling. Also, is there a reason to assert a range of size values instead of the exact number of expected files? |
||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| } // namespace fuzzing | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
callbackis here called unconditionally including on directories. This likely breaks existing behavior and fails the test for the file utility functions. You can run them on your end with the commandbazel test //fuzzing/replay:file_util_testorbazel test //...to run all tests.The direction to detect cycles on a pair of
path_stat.st_dev, path_stat.st_inomakes sense to me.