1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2025-01-19 03:57:14 +01:00

Fixed argument range checking in command manager.

This commit is contained in:
Sandu Liviu Catalin 2015-11-08 21:34:25 +02:00
parent 4e23d3ff88
commit d26b9b560e

View File

@ -176,6 +176,14 @@ void CmdManager::Exec(CmdListener & cmd)
// Command failed // Command failed
return; return;
} }
// The check during the parsing may not count the last argument
else if (cmd.GetMaxArgC() < m_Argc)
{
Error(CMDERR_EXTRANEOUS_ARGS, _SC("Extraneous command arguments: %u < %u"),
cmd.GetMaxArgC(), m_Argc);
// Command failed
return;
}
// Check argument types agains the command specifiers // Check argument types agains the command specifiers
for (Uint32 arg = 0; arg < m_Argc; ++arg) for (Uint32 arg = 0; arg < m_Argc; ++arg)
{ {
@ -236,10 +244,11 @@ bool CmdManager::Parse(SQUint32 max)
// Finished parsing // Finished parsing
break; break;
} }
else if (m_Argc > max) // Early check to prevent parsing unneeded arguments
else if (max < m_Argc)
{ {
Error(CMDERR_EXTRANEOUS_ARGS, _SC("Extraneous command arguments: %u > %u"), Error(CMDERR_EXTRANEOUS_ARGS, _SC("Extraneous command arguments: %u < %u"),
m_Argc, max); max, m_Argc);
// Parsing failed // Parsing failed
good = false; good = false;
// Stop parsing // Stop parsing
@ -378,8 +387,6 @@ bool CmdManager::Parse(SQUint32 max)
// Add it to the argument list along with it's type // Add it to the argument list along with it's type
m_Argv[m_Argc].first = CMDARG_INTEGER; m_Argv[m_Argc].first = CMDARG_INTEGER;
m_Argv[m_Argc].second = var.value; m_Argv[m_Argc].second = var.value;
// Move to the next argument
++m_Argc;
// We've found the correct value // We've found the correct value
found = true; found = true;
} }
@ -405,8 +412,6 @@ bool CmdManager::Parse(SQUint32 max)
// Add it to the argument list along with it's type // Add it to the argument list along with it's type
m_Argv[m_Argc].first = CMDARG_FLOAT; m_Argv[m_Argc].first = CMDARG_FLOAT;
m_Argv[m_Argc].second = var.value; m_Argv[m_Argc].second = var.value;
// Move to the next argument
++m_Argc;
// We've found the correct value // We've found the correct value
found = true; found = true;
} }
@ -428,8 +433,6 @@ bool CmdManager::Parse(SQUint32 max)
// Add it to the argument list along with it's type // Add it to the argument list along with it's type
m_Argv[m_Argc].first = CMDARG_BOOLEAN; m_Argv[m_Argc].first = CMDARG_BOOLEAN;
m_Argv[m_Argc].second = var.value; m_Argv[m_Argc].second = var.value;
// Move to the next argument
++m_Argc;
// We've found the correct value // We've found the correct value
found = true; found = true;
} }
@ -447,8 +450,6 @@ bool CmdManager::Parse(SQUint32 max)
// Add it to the argument list along with it's type // Add it to the argument list along with it's type
m_Argv[m_Argc].first = CMDARG_BOOLEAN; m_Argv[m_Argc].first = CMDARG_BOOLEAN;
m_Argv[m_Argc].second = var.value; m_Argv[m_Argc].second = var.value;
// Move to the next argument
++m_Argc;
// We've found the correct value // We've found the correct value
found = true; found = true;
} }
@ -468,10 +469,10 @@ bool CmdManager::Parse(SQUint32 max)
// Add it to the argument list along with it's type // Add it to the argument list along with it's type
m_Argv[m_Argc].first = CMDARG_STRING; m_Argv[m_Argc].first = CMDARG_STRING;
m_Argv[m_Argc].second = var.value; m_Argv[m_Argc].second = var.value;
}
// Move to the next argument // Move to the next argument
++m_Argc; ++m_Argc;
} }
}
// Save current argument as the previous one // Save current argument as the previous one
pr = ch; pr = ch;
} }