aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r--src/protocol.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 341de0602..71c6bd152 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -1,12 +1,13 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
-// Copyright (c) 2009-2014 The Bitcoin developers
-// Distributed under the MIT/X11 software license, see the accompanying
+// Copyright (c) 2009-2014 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "protocol.h"
#include "chainparams.h"
#include "util.h"
+#include "utilstrencodings.h"
#ifndef WIN32
# include <arpa/inet.h>
@@ -24,7 +25,6 @@ CMessageHeader::CMessageHeader()
{
memcpy(pchMessageStart, Params().MessageStart(), MESSAGE_START_SIZE);
memset(pchCommand, 0, sizeof(pchCommand));
- pchCommand[1] = 1;
nMessageSize = -1;
nChecksum = 0;
}
@@ -32,6 +32,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 +40,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