Merge pull request #40 from nem0/issues
MemoryStream -> Blob fixed possible stack corruption in JSON serialization
This commit is contained in:
commit
026adee662
13 changed files with 43 additions and 41 deletions
|
@ -88,6 +88,7 @@
|
|||
<ClCompile Include="..\..\src\core\base64.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\blob.cpp" />
|
||||
<ClCompile Include="..\..\src\core\crc32.cpp" />
|
||||
<ClCompile Include="..\..\src\core\disk_file_device.cpp" />
|
||||
<ClCompile Include="..\..\src\core\event_manager.cpp" />
|
||||
|
@ -101,7 +102,6 @@
|
|||
<ClCompile Include="..\..\src\core\math_utils.cpp" />
|
||||
<ClCompile Include="..\..\src\core\matrix.cpp" />
|
||||
<ClCompile Include="..\..\src\core\memory_file_device.cpp" />
|
||||
<ClCompile Include="..\..\src\core\memory_stream.cpp" />
|
||||
<ClCompile Include="..\..\src\core\quat.cpp" />
|
||||
<ClCompile Include="..\..\src\core\sha1.cpp">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
|
@ -116,6 +116,7 @@
|
|||
<ClInclude Include="..\..\src\core\base64.h">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\blob.h" />
|
||||
<ClInclude Include="..\..\src\core\crc32.h" />
|
||||
<ClInclude Include="..\..\src\core\delegate.h" />
|
||||
<ClInclude Include="..\..\src\core\disk_file_device.h" />
|
||||
|
@ -138,7 +139,6 @@
|
|||
<ClInclude Include="..\..\src\core\math_utils.h" />
|
||||
<ClInclude Include="..\..\src\core\matrix.h" />
|
||||
<ClInclude Include="..\..\src\core\memory_file_device.h" />
|
||||
<ClInclude Include="..\..\src\core\memory_stream.h" />
|
||||
<ClInclude Include="..\..\src\core\quat.h" />
|
||||
<ClInclude Include="..\..\src\core\sha1.h">
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
<ClCompile Include="..\..\src\core\tcp_stream.cpp">
|
||||
<Filter>Net</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\memory_stream.cpp" />
|
||||
<ClCompile Include="..\..\src\core\tcp_file_device.cpp">
|
||||
<Filter>FS</Filter>
|
||||
</ClCompile>
|
||||
|
@ -39,6 +38,7 @@
|
|||
<ClCompile Include="..\..\src\core\disk_file_device.cpp">
|
||||
<Filter>FS</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\core\blob.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\core\base64.h" />
|
||||
|
@ -81,7 +81,6 @@
|
|||
<ClInclude Include="..\..\src\core\ifile.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\memory_stream.h" />
|
||||
<ClInclude Include="..\..\src\core\ifile_device.h">
|
||||
<Filter>FS</Filter>
|
||||
</ClInclude>
|
||||
|
@ -104,6 +103,7 @@
|
|||
<Filter>MT</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\core\delegate.h" />
|
||||
<ClInclude Include="..\..\src\core\blob.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="FS">
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
#include "memory_stream.h"
|
||||
#include "core/blob.h"
|
||||
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
|
||||
MemoryStream::MemoryStream()
|
||||
Blob::Blob()
|
||||
{
|
||||
m_pos = 0;
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
|
||||
void MemoryStream::write(const void* data, size_t size)
|
||||
void Blob::write(const void* data, size_t size)
|
||||
{
|
||||
if(m_size + (int)size > m_buffer.size())
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ void MemoryStream::write(const void* data, size_t size)
|
|||
}
|
||||
|
||||
|
||||
bool MemoryStream::read(void* data, size_t size)
|
||||
bool Blob::read(void* data, size_t size)
|
||||
{
|
||||
if(m_pos + (int)size > m_size)
|
||||
{
|
|
@ -9,10 +9,10 @@
|
|||
namespace Lux
|
||||
{
|
||||
|
||||
class LUX_CORE_API MemoryStream : public IStream
|
||||
class LUX_CORE_API Blob
|
||||
{
|
||||
public:
|
||||
MemoryStream();
|
||||
Blob();
|
||||
|
||||
void create(void* data, int size) { m_data = data; m_size = size; m_pos = 0; }
|
||||
virtual void write(const void* data, size_t size);
|
|
@ -21,7 +21,8 @@ void JsonSerializer::serialize(const char* label, unsigned int value)
|
|||
{
|
||||
writeBlockComma();
|
||||
char tmp[20];
|
||||
sprintf_s(tmp, "\"%s\" : %u", label, value);
|
||||
writeString(label);
|
||||
sprintf(tmp, " : %u", value);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
@ -30,8 +31,9 @@ void JsonSerializer::serialize(const char* label, unsigned int value)
|
|||
void JsonSerializer::serialize(const char* label, float value)
|
||||
{
|
||||
writeBlockComma();
|
||||
char tmp[100];
|
||||
sprintf_s(tmp, "\"%s\" : %f", label, value);
|
||||
char tmp[20];
|
||||
writeString(label);
|
||||
sprintf(tmp, " : %f", value);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
@ -41,8 +43,9 @@ void JsonSerializer::serialize(const char* label, float value)
|
|||
void JsonSerializer::serialize(const char* label, int value)
|
||||
{
|
||||
writeBlockComma();
|
||||
char tmp[100];
|
||||
sprintf_s(tmp, "\"%s\" : %d", label, value);
|
||||
char tmp[20];
|
||||
writeString(label);
|
||||
sprintf(tmp, " : %d", value);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
@ -110,7 +113,7 @@ void JsonSerializer::serializeArrayItem(unsigned int value)
|
|||
{
|
||||
writeBlockComma();
|
||||
char tmp[20];
|
||||
sprintf_s(tmp, "%u", value);
|
||||
sprintf(tmp, "%u", value);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
@ -120,7 +123,7 @@ void JsonSerializer::serializeArrayItem(int value)
|
|||
{
|
||||
writeBlockComma();
|
||||
char tmp[20];
|
||||
sprintf_s(tmp, "%d", value);
|
||||
sprintf(tmp, "%d", value);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
@ -130,7 +133,7 @@ void JsonSerializer::serializeArrayItem(float value)
|
|||
{
|
||||
writeBlockComma();
|
||||
char tmp[20];
|
||||
sprintf_s(tmp, "%f", value);
|
||||
sprintf(tmp, "%f", value);
|
||||
m_file.write(tmp, strlen(tmp));
|
||||
m_is_first_in_block = false;
|
||||
}
|
||||
|
|
|
@ -38,9 +38,7 @@ namespace Lux
|
|||
char tmp[1024];
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
#pragma warning (disable : 4996)
|
||||
vsnprintf(tmp, 1024, message, args);
|
||||
#pragma warning (default : 4996)
|
||||
|
||||
for(int i = 0, c = m_impl->m_callbacks.size(); i < c; ++i)
|
||||
{
|
||||
|
|
|
@ -60,4 +60,5 @@
|
|||
#define LUX_OVERRIDE override
|
||||
#define LUX_ABSTRACT abstract
|
||||
|
||||
#pragma warning( disable : 4251 )
|
||||
#pragma warning(disable : 4251)
|
||||
#pragma warning(disable : 4996)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "editor_client.h"
|
||||
#include "core/blob.h"
|
||||
#include "core/crc32.h"
|
||||
#include "core/event_manager.h"
|
||||
#include "core/memory_stream.h"
|
||||
#include "core/tcp_connector.h"
|
||||
#include "core/tcp_stream.h"
|
||||
#include "core/vector.h"
|
||||
|
@ -72,7 +72,7 @@ namespace Lux
|
|||
|
||||
void EditorClientImpl::onMessage(uint8_t* data, int size)
|
||||
{
|
||||
MemoryStream stream;
|
||||
Blob stream;
|
||||
stream.create(data, size);
|
||||
int32_t message_type;
|
||||
stream.read(message_type);
|
||||
|
@ -187,7 +187,7 @@ namespace Lux
|
|||
|
||||
void EditorClient::setComponentProperty(const char* component, const char* property, const void* value, int32_t length)
|
||||
{
|
||||
static MemoryStream stream;
|
||||
static Blob stream;
|
||||
stream.clearBuffer();
|
||||
uint32_t tmp = crc32(component);
|
||||
stream.write(&tmp, sizeof(tmp));
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include <Windows.h>
|
||||
#include "Horde3DUtils.h"
|
||||
|
||||
#include "core/blob.h"
|
||||
#include "core/crc32.h"
|
||||
#include "core/file_system.h"
|
||||
#include "core/ifile.h"
|
||||
|
@ -13,7 +14,6 @@
|
|||
#include "core/map.h"
|
||||
#include "core/matrix.h"
|
||||
#include "core/memory_file_device.h"
|
||||
#include "core/memory_stream.h"
|
||||
#include "core/tcp_acceptor.h"
|
||||
#include "core/tcp_stream.h"
|
||||
#include "core/vector.h"
|
||||
|
@ -172,7 +172,7 @@ struct EditorServerImpl
|
|||
MT::Mutex* m_send_mutex;
|
||||
Gizmo m_gizmo;
|
||||
Entity m_selected_entity;
|
||||
MemoryStream m_stream;
|
||||
Blob m_stream;
|
||||
map<uint32_t, vector<PropertyDescriptor> > m_component_properties;
|
||||
map<uint32_t, IPlugin*> m_creators;
|
||||
MouseMode::Value m_mouse_mode;
|
||||
|
@ -922,7 +922,7 @@ const PropertyDescriptor& EditorServerImpl::getPropertyDescriptor(uint32_t type,
|
|||
|
||||
void EditorServerImpl::setProperty(void* data, int size)
|
||||
{
|
||||
MemoryStream stream;
|
||||
Blob stream;
|
||||
stream.create(data, size);
|
||||
uint32_t component_type;
|
||||
stream.read(component_type);
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#include "property_descriptor.h"
|
||||
#include <cstdio>
|
||||
#include "core/istream.h"
|
||||
#include "core/blob.h"
|
||||
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
|
||||
|
||||
void PropertyDescriptor::set(Component cmp, IStream& stream) const
|
||||
void PropertyDescriptor::set(Component cmp, Blob& stream) const
|
||||
{
|
||||
int len;
|
||||
stream.read(&len, sizeof(len));
|
||||
|
@ -51,7 +51,7 @@ void PropertyDescriptor::set(Component cmp, IStream& stream) const
|
|||
}
|
||||
|
||||
|
||||
void PropertyDescriptor::get(Component cmp, IStream& stream) const
|
||||
void PropertyDescriptor::get(Component cmp, Blob& stream) const
|
||||
{
|
||||
int len = 4;
|
||||
switch(m_type)
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace Lux
|
|||
|
||||
|
||||
struct Vec3;
|
||||
class IStream;
|
||||
class Blob;
|
||||
|
||||
|
||||
class PropertyDescriptor
|
||||
|
@ -37,8 +37,8 @@ class PropertyDescriptor
|
|||
PropertyDescriptor(uint32_t _name_hash, BoolGetter _getter, BoolSetter _setter) { m_name_hash = _name_hash; m_bool_getter = _getter; m_bool_setter = _setter; m_type = BOOL; }
|
||||
PropertyDescriptor(uint32_t _name_hash, DecimalGetter _getter, DecimalSetter _setter) { m_name_hash = _name_hash; m_decimal_getter = _getter; m_decimal_setter = _setter; m_type = DECIMAL; }
|
||||
PropertyDescriptor(uint32_t _name_hash, Vec3Getter _getter, Vec3Setter _setter) { m_name_hash = _name_hash; m_vec3_getter = _getter; m_vec3_setter = _setter; m_type = VEC3; }
|
||||
void set(Component cmp, IStream& stream) const;
|
||||
void get(Component cmp, IStream& stream) const;
|
||||
void set(Component cmp, Blob& stream) const;
|
||||
void get(Component cmp, Blob& stream) const;
|
||||
uint32_t getNameHash() const { return m_name_hash; }
|
||||
Type getType() const { return m_type; }
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "server_message_types.h"
|
||||
#include "core/istream.h"
|
||||
#include "core/blob.h"
|
||||
|
||||
|
||||
namespace Lux
|
||||
|
@ -15,7 +15,7 @@ void EntityPositionMessage::write(IStream& stream)
|
|||
}
|
||||
*/
|
||||
|
||||
void EntityPositionEvent::read(IStream& stream)
|
||||
void EntityPositionEvent::read(Blob& stream)
|
||||
{
|
||||
stream.read(&index, sizeof(index));
|
||||
stream.read(&x, sizeof(x));
|
||||
|
@ -36,7 +36,7 @@ void EntitySelectedMessage::write(IStream& stream)
|
|||
}
|
||||
*/
|
||||
|
||||
void EntitySelectedEvent::read(IStream& stream)
|
||||
void EntitySelectedEvent::read(Blob& stream)
|
||||
{
|
||||
stream.read(&index, sizeof(index));
|
||||
int32_t count;
|
||||
|
@ -63,7 +63,7 @@ void PropertyListMessage::write(IStream& stream)
|
|||
}
|
||||
*/
|
||||
|
||||
void PropertyListEvent::read(IStream& stream)
|
||||
void PropertyListEvent::read(Blob& stream)
|
||||
{
|
||||
int32_t count;
|
||||
stream.read(&count, sizeof(count));
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Lux
|
|||
{
|
||||
|
||||
|
||||
class IStream;
|
||||
class Blob;
|
||||
|
||||
|
||||
struct ServerMessageType
|
||||
|
@ -30,7 +30,7 @@ struct LUX_ENGINE_API EntityPositionEvent : public Event
|
|||
EntityPositionEvent() { m_type = ServerMessageType::ENTITY_POSITION; }
|
||||
|
||||
//virtual void write(IStream& stream) LUX_OVERRIDE;
|
||||
void read(IStream& stream);
|
||||
void read(Blob& stream);
|
||||
|
||||
int32_t index;
|
||||
float x;
|
||||
|
@ -44,7 +44,7 @@ struct LUX_ENGINE_API EntitySelectedEvent : public Event
|
|||
EntitySelectedEvent() { m_type = ServerMessageType::ENTITY_SELECTED; }
|
||||
|
||||
//virtual void write(IStream& stream) LUX_OVERRIDE;
|
||||
void read(IStream& stream);
|
||||
void read(Blob& stream);
|
||||
|
||||
int32_t index;
|
||||
vector<uint32_t> components;
|
||||
|
@ -64,7 +64,7 @@ struct LUX_ENGINE_API PropertyListEvent : public Event
|
|||
PropertyListEvent() { m_type = ServerMessageType::PROPERTY_LIST; }
|
||||
|
||||
//virtual void write(IStream& stream) LUX_OVERRIDE;
|
||||
void read(IStream& stream);
|
||||
void read(Blob& stream);
|
||||
|
||||
uint32_t type_hash;
|
||||
vector<Property> properties;
|
||||
|
|
Loading…
Reference in a new issue