mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-16 04:59:41 -04:00
Core/DBLayer: Fixed a few mismatched types and possible invalid memory access with aggregate fields in queries
This commit is contained in:
@@ -2678,7 +2678,7 @@ void ObjectMgr::LoadItemTemplates()
|
||||
itemTemplate.ItemId = itemId;
|
||||
itemTemplate.Class = uint32(fields[1].GetUInt8());
|
||||
itemTemplate.SubClass = uint32(fields[2].GetUInt8());
|
||||
itemTemplate.SoundOverrideSubclass = fields[3].GetInt32();
|
||||
itemTemplate.SoundOverrideSubclass = fields[3].GetInt8();
|
||||
itemTemplate.Name1 = fields[4].GetString();
|
||||
itemTemplate.DisplayInfoID = fields[5].GetUInt32();
|
||||
itemTemplate.Quality = uint32(fields[6].GetUInt8());
|
||||
@@ -6365,11 +6365,11 @@ void ObjectMgr::SetHighestGuids()
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM gameobject");
|
||||
if (result)
|
||||
_gameObjectGuidGenerator.Set((*result)[0].GetUInt32() + 1);
|
||||
_gameObjectGuidGenerator.Set((*result)[0].GetUInt64() + 1);
|
||||
|
||||
result = WorldDatabase.Query("SELECT MAX(guid) FROM transports");
|
||||
if (result)
|
||||
_moTransportGuidGenerator.Set((*result)[0].GetUInt32() + 1);
|
||||
_moTransportGuidGenerator.Set((*result)[0].GetUInt64() + 1);
|
||||
|
||||
result = CharacterDatabase.Query("SELECT MAX(id) FROM auctionhouse");
|
||||
if (result)
|
||||
@@ -8832,8 +8832,8 @@ void ObjectMgr::LoadCreatureClassLevelStats()
|
||||
}
|
||||
}
|
||||
|
||||
stats.BaseMana = fields[8].GetUInt16();
|
||||
stats.BaseArmor = fields[9].GetUInt16();
|
||||
stats.BaseMana = fields[8].GetUInt32();
|
||||
stats.BaseArmor = fields[9].GetUInt32();
|
||||
|
||||
stats.AttackPower = fields[10].GetUInt16();
|
||||
stats.RangedAttackPower = fields[11].GetUInt16();
|
||||
|
||||
@@ -46,7 +46,7 @@ void Field::SetByteValue(const void* newValue, const size_t newSize, enum_field_
|
||||
data.raw = true;
|
||||
}
|
||||
|
||||
void Field::SetStructuredValue(char* newValue, enum_field_types newType, uint32 length, bool isBinary)
|
||||
void Field::SetStructuredValue(char* newValue, enum_field_types newType, uint32 length)
|
||||
{
|
||||
if (data.value)
|
||||
CleanUp();
|
||||
@@ -54,15 +54,9 @@ void Field::SetStructuredValue(char* newValue, enum_field_types newType, uint32
|
||||
// This value stores somewhat structured data that needs function style casting
|
||||
if (newValue)
|
||||
{
|
||||
if (!isBinary)
|
||||
{
|
||||
data.value = new char[length + 1];
|
||||
*(reinterpret_cast<char*>(data.value) + length) = '\0';
|
||||
}
|
||||
else
|
||||
data.value = new char[length];
|
||||
|
||||
data.value = new char[length + 1];
|
||||
memcpy(data.value, newValue, length);
|
||||
*(reinterpret_cast<char*>(data.value) + length) = '\0';
|
||||
data.length = length;
|
||||
}
|
||||
|
||||
|
||||
@@ -239,9 +239,11 @@ class Field
|
||||
{
|
||||
char const* string = GetCString();
|
||||
if (!string)
|
||||
string = "";
|
||||
return "";
|
||||
|
||||
return std::string(string, data.length);
|
||||
}
|
||||
|
||||
return std::string((char*)data.value, data.length);
|
||||
}
|
||||
|
||||
@@ -284,7 +286,7 @@ class Field
|
||||
#endif
|
||||
|
||||
void SetByteValue(void const* newValue, size_t const newSize, enum_field_types newType, uint32 length);
|
||||
void SetStructuredValue(char* newValue, enum_field_types newType, uint32 length, bool isBinary);
|
||||
void SetStructuredValue(char* newValue, enum_field_types newType, uint32 length);
|
||||
|
||||
void CleanUp()
|
||||
{
|
||||
|
||||
@@ -72,6 +72,7 @@ void PreparedStatement::BindParameters()
|
||||
break;
|
||||
case TYPE_BINARY:
|
||||
m_stmt->setBinary(i, statement_data[i].binary, false);
|
||||
break;
|
||||
case TYPE_NULL:
|
||||
m_stmt->setNull(i);
|
||||
break;
|
||||
@@ -357,7 +358,7 @@ void MySQLPreparedStatement::setBinary(const uint8 index, const std::vector<uint
|
||||
m_paramsSet[index] = true;
|
||||
MYSQL_BIND* param = &m_bind[index];
|
||||
size_t len = value.size();
|
||||
param->buffer_type = MYSQL_TYPE_VAR_STRING;
|
||||
param->buffer_type = MYSQL_TYPE_BLOB;
|
||||
delete [] static_cast<char *>(param->buffer);
|
||||
param->buffer = new char[len];
|
||||
param->buffer_length = len;
|
||||
@@ -365,7 +366,10 @@ void MySQLPreparedStatement::setBinary(const uint8 index, const std::vector<uint
|
||||
delete param->length;
|
||||
param->length = new unsigned long(len);
|
||||
if (isString)
|
||||
{
|
||||
*param->length -= 1;
|
||||
param->buffer_type = MYSQL_TYPE_VAR_STRING;
|
||||
}
|
||||
|
||||
memcpy(param->buffer, value.data(), len);
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ bool ResultSet::NextRow()
|
||||
}
|
||||
|
||||
for (uint32 i = 0; i < _fieldCount; i++)
|
||||
_currentRow[i].SetStructuredValue(row[i], _fields[i].type, lengths[i], (_fields[i].flags & BINARY_FLAG) != 0);
|
||||
_currentRow[i].SetStructuredValue(row[i], _fields[i].type, lengths[i]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user