1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2026-02-14 02:07:14 +01:00

Prevent server crash by accessing row data from MySQL result-set when there is no valid row available. Throw an error instead. Should close #25

This commit is contained in:
Sandu Liviu Catalin
2016-07-28 00:41:43 +03:00
parent 0b6f817e1f
commit 8ce40ee74c
5 changed files with 173 additions and 34 deletions

View File

@@ -19,6 +19,7 @@ SQInteger ResultSet::Typename(HSQUIRRELVM vm)
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
void ResultSet::Validate(CCStr file, Int32 line) const
{
// Do we have a valid result-set handle?
if (!m_Handle)
{
SqThrowF("Invalid MySQL result-set reference =>[%s:%d]", file, line);
@@ -27,6 +28,7 @@ void ResultSet::Validate(CCStr file, Int32 line) const
#else
void ResultSet::Validate() const
{
// Do we have a valid result-set handle?
if (!m_Handle)
{
SqThrowF("Invalid MySQL result-set reference");
@@ -38,6 +40,7 @@ void ResultSet::Validate() const
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
void ResultSet::ValidateCreated(CCStr file, Int32 line) const
{
// Do we have a valid result-set handle?
if (!m_Handle)
{
SqThrowF("Invalid MySQL result-set reference =>[%s:%d]", file, line);
@@ -50,6 +53,7 @@ void ResultSet::ValidateCreated(CCStr file, Int32 line) const
#else
void ResultSet::ValidateCreated() const
{
// Do we have a valid result-set handle?
if (!m_Handle)
{
SqThrowF("Invalid MySQL result-set reference");
@@ -61,6 +65,37 @@ void ResultSet::ValidateCreated() const
}
#endif // _DEBUG
// ------------------------------------------------------------------------------------------------
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
void ResultSet::ValidateStepped(CCStr file, Int32 line) const
{
// Do we have a valid result-set handle?
if (!m_Handle)
{
SqThrowF("Invalid MySQL result-set reference =>[%s:%d]", file, line);
}
// Do we have a valid row available?
else if (m_Handle->mRow == nullptr)
{
SqThrowF("No row available in MySQL result-set =>[%s:%d]", file, line);
}
}
#else
void ResultSet::ValidateStepped() const
{
// Do we have a valid result-set handle?
if (!m_Handle)
{
SqThrowF("Invalid MySQL result-set reference");
}
// Do we have a valid row available?
else if (m_Handle->mRow == nullptr)
{
SqThrowF("No row available in MySQL result-set");
}
}
#endif // _DEBUG
// ------------------------------------------------------------------------------------------------
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
const ResRef & ResultSet::GetValid(CCStr file, Int32 line) const
@@ -91,6 +126,21 @@ const ResRef & ResultSet::GetCreated() const
}
#endif // _DEBUG
// ------------------------------------------------------------------------------------------------
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
const ResRef & ResultSet::GetStepped(CCStr file, Int32 line) const
{
ValidateStepped(file, line);
return m_Handle;
}
#else
const ResRef & ResultSet::GetStepped() const
{
ValidateStepped();
return m_Handle;
}
#endif // _DEBUG
// ------------------------------------------------------------------------------------------------
#if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC)
void ResultSet::ValidateField(Int32 idx, CCStr file, Int32 line) const