Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F10615061
D1743.id4951.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
D1743.id4951.diff
View Options
diff --git a/src/net.cpp b/src/net.cpp
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -755,7 +755,7 @@
// Store received bytes per message command to prevent a memory DOS,
// only allow valid commands.
mapMsgCmdSize::iterator i =
- mapRecvBytesPerMsgCmd.find(msg.hdr.pchCommand);
+ mapRecvBytesPerMsgCmd.find(msg.hdr.pchCommand.data());
if (i == mapRecvBytesPerMsgCmd.end()) {
i = mapRecvBytesPerMsgCmd.find(NET_MESSAGE_COMMAND_OTHER);
}
diff --git a/src/protocol.h b/src/protocol.h
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -69,7 +69,7 @@
}
MessageMagic pchMessageStart;
- char pchCommand[COMMAND_SIZE];
+ std::array<char, COMMAND_SIZE> pchCommand;
uint32_t nMessageSize;
uint8_t pchChecksum[CHECKSUM_SIZE];
};
diff --git a/src/protocol.cpp b/src/protocol.cpp
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -71,7 +71,7 @@
CMessageHeader::CMessageHeader(const MessageMagic &pchMessageStartIn) {
memcpy(std::begin(pchMessageStart), std::begin(pchMessageStartIn),
MESSAGE_START_SIZE);
- memset(pchCommand, 0, sizeof(pchCommand));
+ memset(pchCommand.data(), 0, sizeof(pchCommand));
nMessageSize = -1;
memset(pchChecksum, 0, CHECKSUM_SIZE);
}
@@ -81,15 +81,17 @@
unsigned int nMessageSizeIn) {
memcpy(std::begin(pchMessageStart), std::begin(pchMessageStartIn),
MESSAGE_START_SIZE);
- memset(pchCommand, 0, sizeof(pchCommand));
- strncpy(pchCommand, pszCommand, COMMAND_SIZE);
+ memset(pchCommand.data(), 0, sizeof(pchCommand));
+ strncpy(pchCommand.data(), pszCommand, COMMAND_SIZE);
nMessageSize = nMessageSizeIn;
memset(pchChecksum, 0, CHECKSUM_SIZE);
}
std::string CMessageHeader::GetCommand() const {
- return std::string(pchCommand,
- pchCommand + strnlen(pchCommand, COMMAND_SIZE));
+ // return std::string(pchCommand.begin(), pchCommand.end());
+ return std::string(pchCommand.data(),
+ pchCommand.data() +
+ strnlen(pchCommand.data(), COMMAND_SIZE));
}
static bool
@@ -102,11 +104,11 @@
}
// Check the command string for errors
- for (const char *p1 = header.pchCommand;
- p1 < header.pchCommand + CMessageHeader::COMMAND_SIZE; p1++) {
+ for (const char *p1 = header.pchCommand.data();
+ p1 < header.pchCommand.data() + CMessageHeader::COMMAND_SIZE; p1++) {
if (*p1 == 0) {
// Must be all zeros after the first zero
- for (; p1 < header.pchCommand + CMessageHeader::COMMAND_SIZE;
+ for (; p1 < header.pchCommand.data() + CMessageHeader::COMMAND_SIZE;
p1++) {
if (*p1 != 0) {
return false;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 09:55 (11 h, 18 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4559195
Default Alt Text
D1743.id4951.diff (2 KB)
Attached To
D1743: Changed CMessageHeader::pchCommand to use a C++11 array and updated its various uses to reflect this.
Event Timeline
Log In to Comment