Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,7 @@ Result<Status> AuditFileRegexMatch(const AuditFileRegexMatchParams& params, Indi
if (0 != stat((params.path + "/" + entry->d_name).c_str(), &st))
{
const int status = errno;
OsConfigLogInfo(context.GetLogHandle(), "Failed to stat file '%s/%s': %s", params.path.c_str(), entry->d_name, strerror(status));
errorCount++;
Comment thread
robertwoj-microsoft marked this conversation as resolved.
OsConfigLogInfo(context.GetLogHandle(), "Failed to stat symlink target '%s/%s': %s", params.path.c_str(), entry->d_name, strerror(status));
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,3 +588,24 @@ TEST_F(FileRegexMatchTest, Audit_SymlinkFollow_Directory)
ASSERT_TRUE(result.HasValue());
EXPECT_EQ(result.Value(), Status::Compliant);
}

TEST_F(FileRegexMatchTest, Audit_SymlinkFollow_DanglingLink)
{
MakeTempfile("test");
const auto targetFilename = mTempfiles.back();
const auto linkFilename = targetFilename + ".link";

AuditFileRegexMatchParams params;
params.path = mTempdir;
params.filenamePattern = regex(".*\\.link");
params.matchOperation = Operation::Match;
params.matchPattern = R"(^foo$)"; // pattern mismatch against 'test'
params.behavior = Behavior::AtLeastOneExists;

ASSERT_EQ(0, symlink(targetFilename.c_str(), linkFilename.c_str()));
EXPECT_EQ(0, unlink(targetFilename.c_str()));
auto result = AuditFileRegexMatch(params, mIndicators, mContext);
EXPECT_EQ(0, unlink(linkFilename.c_str()));
ASSERT_TRUE(result.HasValue());
EXPECT_EQ(result.Value(), Status::NonCompliant);
}
Loading