From 87ffa39752c0c11abeece044bad95d257ed6000e Mon Sep 17 00:00:00 2001 From: sambaby <1337922982@qq.com> Date: Tue, 29 Aug 2023 18:24:21 +0800 Subject: [PATCH] fixed 1c2654d from https://gitee.com/fupengfei001/tools_previewer/pulls/117 add param string length check Signed-off-by: sambaby <1337922982@qq.com> --- RichPreviewer.cpp | 4 +++- ThinPreviewer.cpp | 2 ++ util/CommandParser.cpp | 10 ++++++++++ util/CommandParser.h | 2 ++ 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/RichPreviewer.cpp b/RichPreviewer.cpp index 5dedc85..5ffc1f8 100644 --- a/RichPreviewer.cpp +++ b/RichPreviewer.cpp @@ -159,13 +159,15 @@ int main(int argc, char* argv[]) CommandParser& parser = CommandParser::GetInstance(); vector strs; for (int i = 1; i < argc; ++i) { + if (parser.IsMainArgLengthInvalid(argv[i])) + return START_PARAM_INVALID_CODE; strs.push_back(argv[i]); } if (!parser.ProcessCommand(strs)) { return 0; } - + // check params if (!parser.IsCommandValid()) { return START_PARAM_INVALID_CODE; } diff --git a/ThinPreviewer.cpp b/ThinPreviewer.cpp index d2116d7..57b44f9 100644 --- a/ThinPreviewer.cpp +++ b/ThinPreviewer.cpp @@ -149,6 +149,8 @@ int main(int argc, char* argv[]) CommandParser& parser = CommandParser::GetInstance(); vector strs; for (int i = 1; i < argc; ++i) { + if (parser.IsMainArgLengthInvalid(argv[i])) + return START_PARAM_INVALID_CODE; strs.push_back(argv[i]); } diff --git a/util/CommandParser.cpp b/util/CommandParser.cpp index 9a662c0..1be3a70 100644 --- a/util/CommandParser.cpp +++ b/util/CommandParser.cpp @@ -848,4 +848,14 @@ bool CommandParser::IsStaticCardValid() staticCard = true; } return true; +} + +bool CommandParser::IsMainArgLengthInvalid(const char* str) const +{ + size_t argLength = strlen(str); + if (argLength > maxMainArgLength) { + ELOG("param size is more than %d", maxMainArgLength); + return true; + } + return false; } \ No newline at end of file diff --git a/util/CommandParser.h b/util/CommandParser.h index 015dbd6..a941eb6 100644 --- a/util/CommandParser.h +++ b/util/CommandParser.h @@ -58,6 +58,7 @@ public: bool IsComponentMode() const; std::string GetAbilityPath() const; bool IsStaticCard() const; + bool IsMainArgLengthInvalid(const char* str) const; private: CommandParser(); @@ -112,6 +113,7 @@ private: bool isComponentMode; std::string abilityPath; bool staticCard; + const size_t maxMainArgLength = 1024; bool IsDebugPortValid(); bool IsAppPathValid();