aboutsummaryrefslogtreecommitdiff
path: root/src/server/scripts/Commands
diff options
context:
space:
mode:
authorGiacomo Pozzoni <giacomopoz@gmail.com>2021-01-24 16:04:47 +0100
committerGitHub <noreply@github.com>2021-01-24 16:04:47 +0100
commit661f554b9e08a3721227f1e4a4fe6fd74e43a1f4 (patch)
tree16caa4dab3e052ba563212b4f8ef4bdf4af7b5fc /src/server/scripts/Commands
parent62320b1efab3a050cf2187490b59234a037c69c8 (diff)
Core/Misc: Fix static analysis issues (#25924)
* Core/Misc: Fix static analysis issues * Fix infinite loop in ".debug send opcode" Fix using uninitialized memory in ".debug send opcode"
Diffstat (limited to 'src/server/scripts/Commands')
-rw-r--r--src/server/scripts/Commands/cs_debug.cpp95
1 files changed, 64 insertions, 31 deletions
diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp
index 4d25885d910..05d970cf4a9 100644
--- a/src/server/scripts/Commands/cs_debug.cpp
+++ b/src/server/scripts/Commands/cs_debug.cpp
@@ -272,49 +272,63 @@ public:
std::stringstream parsedStream;
while (!ifs.eof())
{
- char commentToken[2];
+ char commentToken[2] = {};
ifs.get(commentToken[0]);
- if (commentToken[0] == '/' && !ifs.eof())
+ if (ifs.eof())
+ break;
+ if (commentToken[0] == '/')
{
ifs.get(commentToken[1]);
- // /* comment
- if (commentToken[1] == '*')
+ if (!ifs.eof())
{
- while (!ifs.eof())
+ // /* comment
+ if (commentToken[1] == '*')
{
- ifs.get(commentToken[0]);
- if (commentToken[0] == '*' && !ifs.eof())
+ while (!ifs.eof())
{
- ifs.get(commentToken[1]);
- if (commentToken[1] == '/')
+ ifs.get(commentToken[0]);
+ if (ifs.eof())
break;
- else
- ifs.putback(commentToken[1]);
+ if (commentToken[0] == '*')
+ {
+ ifs.get(commentToken[1]);
+ if (ifs.eof())
+ break;
+ if (commentToken[1] == '/')
+ break;
+ else
+ ifs.putback(commentToken[1]);
+ }
}
+ continue;
}
- continue;
- }
- // line comment
- else if (commentToken[1] == '/')
- {
- std::string str;
- std::getline(ifs, str);
- continue;
+ // line comment
+ else if (commentToken[1] == '/')
+ {
+ std::string str;
+ std::getline(ifs, str);
+ if (ifs.eof())
+ break;
+ continue;
+ }
+ // regular data
+ else
+ ifs.putback(commentToken[1]);
}
- // regular data
- else
- ifs.putback(commentToken[1]);
}
parsedStream.put(commentToken[0]);
}
ifs.close();
- uint32 opcode;
+ uint32 opcode = 0;
parsedStream >> opcode;
+ if (!opcode)
+ return false;
+
WorldPacket data(opcode, 0);
- while (!parsedStream.eof())
+ while (!parsedStream.eof() && !parsedStream.fail())
{
std::string type;
parsedStream >> type;
@@ -324,38 +338,59 @@ public:
if (type == "uint8")
{
- uint16 val1;
+ if (parsedStream.eof())
+ return false;
+ uint16 val1 = 0;
parsedStream >> val1;
+ if (parsedStream.fail())
+ return false;
data << uint8(val1);
}
else if (type == "uint16")
{
- uint16 val2;
+ if (parsedStream.eof())
+ return false;
+ uint16 val2 = 0;
parsedStream >> val2;
+ if (parsedStream.fail())
+ return false;
data << val2;
}
else if (type == "uint32")
{
- uint32 val3;
+ if (parsedStream.eof())
+ return false;
+ uint32 val3 = 0;
parsedStream >> val3;
+ if (parsedStream.fail())
+ return false;
data << val3;
}
else if (type == "uint64")
{
- uint64 val4;
+ if (parsedStream.eof())
+ return false;
+ uint64 val4 = 0;
parsedStream >> val4;
+ if (parsedStream.fail())
+ return false;
data << val4;
}
else if (type == "float")
{
- float val5;
+ if (parsedStream.eof())
+ return false;
+ float val5 = 0.0f;
parsedStream >> val5;
+ if (parsedStream.fail())
+ return false;
data << val5;
}
else if (type == "string")
{
std::string val6;
parsedStream >> val6;
+ // empty string is allowed so no need to check eof/fail here
data << val6;
}
else if (type == "appitsguid")
@@ -373,7 +408,6 @@ public:
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, 0);
handler->SetSentErrorMessage(true);
- ifs.close();
return false;
}
data << obj->GetPackGUID();
@@ -385,7 +419,6 @@ public:
{
handler->PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, 0);
handler->SetSentErrorMessage(true);
- ifs.close();
return false;
}
data << uint64(obj->GetGUID());