add param string length check

Signed-off-by: sambaby <1337922982@qq.com>
This commit is contained in:
sambaby
2023-08-29 18:24:21 +08:00
parent 2785ff6adb
commit 1c2654dcf1
4 changed files with 17 additions and 1 deletions
+3 -1
View File
@@ -159,13 +159,15 @@ int main(int argc, char* argv[])
CommandParser& parser = CommandParser::GetInstance();
vector<string> 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;
}
+2
View File
@@ -149,6 +149,8 @@ int main(int argc, char* argv[])
CommandParser& parser = CommandParser::GetInstance();
vector<string> strs;
for (int i = 1; i < argc; ++i) {
if (parser.IsMainArgLengthInvalid(argv[i]))
return START_PARAM_INVALID_CODE;
strs.push_back(argv[i]);
}
+10
View File
@@ -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;
}
+2
View File
@@ -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();