Replace strlen with strnlen in native code (#5510)
* fix expected vs actual for easier troubleshooting * replace strlen calls with strnlen
This commit is contained in:
parent
227da48490
commit
9559694191
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
TEST_F(CreateSymLinkTest, SymLinkToDirectory)
|
||||
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue