[PlayStation] Specify byte order clearly on Remote Inspector Protocol
authorbasuke.suzuki@sony.com <basuke.suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2019 01:19:28 +0000 (01:19 +0000)
committerbasuke.suzuki@sony.com <basuke.suzuki@sony.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 11 Apr 2019 01:19:28 +0000 (01:19 +0000)
https://bugs.webkit.org/show_bug.cgi?id=196790

Reviewed by Ross Kirsling.

Original implementation lacks byte order specification. Network byte order is the
good candidate if there's no strong reason to choose other.
Currently no client exists for PlayStation remote inspector protocol, so we can
change the byte order without care.

* inspector/remote/playstation/RemoteInspectorMessageParserPlayStation.cpp:
(Inspector::MessageParser::createMessage):
(Inspector::MessageParser::parse):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@244176 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/remote/playstation/RemoteInspectorMessageParserPlayStation.cpp

index 8820e2a..365e1d2 100644 (file)
@@ -1,3 +1,19 @@
+2019-04-10  Basuke Suzuki  <basuke.suzuki@sony.com>
+
+        [PlayStation] Specify byte order clearly on Remote Inspector Protocol
+        https://bugs.webkit.org/show_bug.cgi?id=196790
+
+        Reviewed by Ross Kirsling.
+
+        Original implementation lacks byte order specification. Network byte order is the
+        good candidate if there's no strong reason to choose other.
+        Currently no client exists for PlayStation remote inspector protocol, so we can
+        change the byte order without care.
+
+        * inspector/remote/playstation/RemoteInspectorMessageParserPlayStation.cpp:
+        (Inspector::MessageParser::createMessage):
+        (Inspector::MessageParser::parse):
+
 2019-04-10  Devin Rousso  <drousso@apple.com>
 
        Web Inspector: Inspector: lazily create the agent
index 8540170..ab2d461 100644 (file)
@@ -26,6 +26,8 @@
 #include "config.h"
 #include "RemoteInspectorMessageParser.h"
 
+#include <netinet/in.h>
+
 #if ENABLE(REMOTE_INSPECTOR)
 
 namespace Inspector {
@@ -34,7 +36,7 @@ namespace Inspector {
 | <--- one message for send / didReceiveData ---> |
 +--------------+----------------------------------+--------------
 |    size      |               data               | (next message)
-|    4byte     |          variable length         |
+|  4byte (NBO) |          variable length         |
 +--------------+----------------------------------+--------------
                | <------------ size ------------> |
 */
@@ -52,7 +54,8 @@ Vector<uint8_t> MessageParser::createMessage(const uint8_t* data, size_t size)
 
     auto messageBuffer = Vector<uint8_t>(size + sizeof(uint32_t));
     uint32_t uintSize = static_cast<uint32_t>(size);
-    memcpy(&messageBuffer[0], &uintSize, sizeof(uint32_t));
+    uint32_t nboSize = htonl(uintSize);
+    memcpy(&messageBuffer[0], &nboSize, sizeof(uint32_t));
     memcpy(&messageBuffer[sizeof(uint32_t)], data, uintSize);
     return messageBuffer;
 }
@@ -84,6 +87,7 @@ bool MessageParser::parse()
 
         uint32_t dataSize = 0;
         memcpy(&dataSize, &m_buffer[0], sizeof(uint32_t));
+        dataSize = ntohl(dataSize);
         if (!dataSize) {
             LOG_ERROR("Message Parser received an invalid message size");
             return false;