Fix string serialization bug on big-endian machines 52/39052/3
authorRafal Krypa <r.krypa@samsung.com>
Thu, 7 May 2015 13:04:41 +0000 (15:04 +0200)
committerLukasz Wojciechowski <l.wojciechow@partner.samsung.com>
Fri, 8 May 2015 09:27:03 +0000 (02:27 -0700)
Function serializing string first converted its size to little-endian and
then used the converted value as actual size. This could have worked only
on little-endian machines and could cause undefined behaviour on big-endian.

Change-Id: Ica742b1d33b14e056f8c2322e39ffd7371e7ae14
Signed-off-by: Rafal Krypa <r.krypa@samsung.com>
src/common/protocol/ProtocolSerialization.h

index 8340cf9..3d444cd 100644 (file)
@@ -91,7 +91,7 @@ struct ProtocolSerialization {
     static void serialize(IStream &stream, const std::string &str) {
         uint32_t length = htole32(static_cast<uint32_t>(str.size()));
         stream.write(sizeof(length), &length);
-        stream.write(length, str.c_str());
+        stream.write(str.size(), str.c_str());
     }
     static void serializeNoSize(IStream &stream, const std::string &str) {
         int length = str.size();