App: Sanitize all paths for null characters (#23821)
* App: Sanitize all paths for null characters * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestions from code review --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Kacper Donat <kadet1090@gmail.com>
This commit is contained in:
@@ -52,6 +52,11 @@ public:
|
||||
{
|
||||
return extractVersionFromConfigMap(config);
|
||||
}
|
||||
|
||||
static std::filesystem::path wrapSanitizePath(const std::string& pathAsString)
|
||||
{
|
||||
return sanitizePath(pathAsString);
|
||||
}
|
||||
};
|
||||
|
||||
class ApplicationDirectoriesTest: public ::testing::Test
|
||||
@@ -747,6 +752,25 @@ TEST_F(ApplicationDirectoriesTest, extractVersionNegativeNumbersPassThrough)
|
||||
EXPECT_EQ(min, -7);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(ApplicationDirectoriesTest, sanitizeRemovesNullCharacterAtEnd)
|
||||
{
|
||||
std::string input = std::string("valid_path") + '\0' + "junk_after";
|
||||
std::filesystem::path result = ApplicationDirectoriesTestClass::wrapSanitizePath(input);
|
||||
|
||||
EXPECT_EQ(result.string(), "valid_path");
|
||||
EXPECT_EQ(result.string().find('\0'), std::string::npos);
|
||||
}
|
||||
|
||||
TEST_F(ApplicationDirectoriesTest, sanitizeReturnsUnchangedIfNoNullCharacter)
|
||||
{
|
||||
std::string input = "clean_path/without_nulls";
|
||||
std::filesystem::path result = ApplicationDirectoriesTestClass::wrapSanitizePath(input);
|
||||
|
||||
EXPECT_EQ(result.string(), input);
|
||||
EXPECT_EQ(result.string().find('\0'), std::string::npos);
|
||||
}
|
||||
|
||||
/* NOLINTEND(
|
||||
readability-magic-numbers,
|
||||
cppcoreguidelines-avoid-magic-numbers,
|
||||
|
||||
Reference in New Issue
Block a user