Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions source/common/filesystem/filesystem_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ ssize_t fileSize(const std::string& path) {
}

std::string fileReadToEnd(const std::string& path) {
if (illegalPath(path)) {
throw EnvoyException(fmt::format("Invalid path: {}", path));
}

std::ios::sync_with_stdio(false);

std::ifstream file(path);
Expand Down
2 changes: 1 addition & 1 deletion source/common/filesystem/filesystem_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ ssize_t fileSize(const std::string& path);

/**
* @return full file content as a string.
* @throw EnvoyException if the file cannot be read.
* @throw EnvoyException if the file cannot be read, or if the path is blacklisted.
* Be aware, this is not most highly performing file reading method.
*/
std::string fileReadToEnd(const std::string& path);
Expand Down
4 changes: 4 additions & 0 deletions test/common/filesystem/filesystem_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ TEST_F(FileSystemImplTest, fileReadToEndDoesNotExist) {
EnvoyException);
}

TEST_F(FileSystemImplTest, fileReadToEndBlacklisted) {
EXPECT_THROW(Filesystem::fileReadToEnd("/dev/urandom"), EnvoyException);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add tests for /proc and /sys?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

}

TEST_F(FileSystemImplTest, CanonicalPathSuccess) {
EXPECT_EQ("/", Filesystem::canonicalPath("//"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ TEST_F(InjectedResourceMonitorTest, ReportsErrorForOutOfRangePressure) {
}

TEST_F(InjectedResourceMonitorTest, ReportsErrorOnFileRead) {
EXPECT_CALL(cb_, onFailure(ExceptionContains("unable to read file")));
EXPECT_CALL(cb_, onFailure(ExceptionContains("Invalid path")));
monitor_->updateResourceUsage(cb_);
}

Expand Down