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
2 changes: 1 addition & 1 deletion src/libpsl-native/src/followsymlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ char* FollowSymLink(const char* fileName)

if (realPath)
{
return strndup(realPath, strlen(realPath) + 1);
return strndup(realPath, strnlen(realPath, PATH_MAX));
}

// if the path wasn't resolved, use readlink
Expand Down
2 changes: 1 addition & 1 deletion src/libpsl-native/src/getfullyqualifiedname.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ char *GetFullyQualifiedName()
}

// return the first canonical name in the list
fullName = strndup(info->ai_canonname, strlen(info->ai_canonname));
fullName = strndup(info->ai_canonname, strnlen(info->ai_canonname, NI_MAXHOST));

// only free info if getaddrinfo was successful
freeaddrinfo(info);
Expand Down
4 changes: 2 additions & 2 deletions src/libpsl-native/test/test-createsymlink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ TEST_F(CreateSymLinkTest, SymLinkToFile)
std::string target = FollowSymLink(fileSymLink.c_str());
char buffer[PATH_MAX];
std::string expected = realpath(file, buffer);
EXPECT_EQ(target, expected);
EXPECT_EQ(expected, target);
Copy link
Member

Choose a reason for hiding this comment

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

Can you please explain a bit about why you made the changes to EXPECT_EQ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The pattern for EXPECT_EQ is EXPECT_EQ(<expected>,<actual>) when you call it with the parameters reverse it makes the error very confusing.

}

TEST_F(CreateSymLinkTest, SymLinkToDirectory)
Expand All @@ -103,7 +103,7 @@ TEST_F(CreateSymLinkTest, SymLinkToDirectory)
std::string target = FollowSymLink(dirSymLink.c_str());
char buffer[PATH_MAX];
std::string expected = realpath(dir, buffer);
EXPECT_EQ(target, expected);
EXPECT_EQ(expected, target);
}

TEST_F(CreateSymLinkTest, SymLinkAgain)
Expand Down