diff options
author | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-09-16 18:13:05 +0200 |
---|---|---|
committer | Wladimir J. van der Laan <laanwj@gmail.com> | 2014-09-18 10:15:48 +0200 |
commit | 62e5f8f96114a872354103ef566b5c74a16154d4 (patch) | |
tree | 08c946da5a14b1e98bf83234f625973ae7dd8c30 /src/protocol.cpp | |
parent | c14bfea8eee5498f3c7d4f582b6fb7ac18ec1a62 (diff) |
CMessageHeader sanity changes
- Remove spurious `pchCommand[1] = 1` in CMessageHeader()
- Make sure that pchCommand is zero-padded if length is shorter than
COMMAND_SIZE
- Use strnlen to determine length of pcmCommand in GetCommand
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r-- | src/protocol.cpp | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp index 341de0602a..0e28f3abbd 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -24,7 +24,6 @@ CMessageHeader::CMessageHeader() { memcpy(pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE); memset(pchCommand, 0, sizeof(pchCommand)); - pchCommand[1] = 1; nMessageSize = -1; nChecksum = 0; } @@ -32,6 +31,7 @@ CMessageHeader::CMessageHeader() CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSizeIn) { memcpy(pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE); + memset(pchCommand, 0, sizeof(pchCommand)); strncpy(pchCommand, pszCommand, COMMAND_SIZE); nMessageSize = nMessageSizeIn; nChecksum = 0; @@ -39,10 +39,7 @@ CMessageHeader::CMessageHeader(const char* pszCommand, unsigned int nMessageSize std::string CMessageHeader::GetCommand() const { - if (pchCommand[COMMAND_SIZE-1] == 0) - return std::string(pchCommand, pchCommand + strlen(pchCommand)); - else - return std::string(pchCommand, pchCommand + COMMAND_SIZE); + return std::string(pchCommand, pchCommand + strnlen(pchCommand, COMMAND_SIZE)); } bool CMessageHeader::IsValid() const |