aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <[email protected]>2020-03-27 19:54:49 +0100
committerWladimir J. van der Laan <[email protected]>2020-03-27 20:04:46 +0100
commitf2c416bcf5f898dd996106871dbbd7051851ccac (patch)
tree08a5302915dddef956f6fe35809a35a96947565d /src/protocol.cpp
parentMerge #18447: test: Add coverage for script parse error in ParseScript (diff)
parentrefactor: Work around GCC 9 `-Wredundant-move` warning (diff)
downloaddiscoin-f2c416bcf5f898dd996106871dbbd7051851ccac.tar.xz
discoin-f2c416bcf5f898dd996106871dbbd7051851ccac.zip
Merge #16995: Fix gcc 9 warnings
ff9c671b11d40e5d0623eff3dd12e48cbaafb34e refactor: Work around GCC 9 `-Wredundant-move` warning (Russell Yanofsky) b837b334db5dd6232725fd2350928ff4fbd3feee net: Fail instead of truncate command name in CMessageHeader (Wladimir J. van der Laan) Pull request description: Fixes all 3 from #16992 (see commits) - net: Fail instead of truncate command name in CMessageHeader - refactor: Use std::move workaround for unique_ptr upcast only when necessary ACKs for top commit: practicalswift: ACK ff9c671b11d40e5d0623eff3dd12e48cbaafb34e -- patch looks correct sipa: utACK ff9c671b11d40e5d0623eff3dd12e48cbaafb34e ryanofsky: Code review ACK ff9c671b11d40e5d0623eff3dd12e48cbaafb34e. Looks good and seems to pass travis, modulo a timeout on one build hebasto: ACK ff9c671b11d40e5d0623eff3dd12e48cbaafb34e, tested on Fedora 31: Tree-SHA512: 52d8c13aaf0d56f9bc546a98d7f853eae21f7e325b202fdeb2286b19a9a0ee308634c644b039f60ad8043421e382381cbf1bce58d9f807547f928621c7d245d0
Diffstat (limited to 'src/protocol.cpp')
-rw-r--r--src/protocol.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/protocol.cpp b/src/protocol.cpp
index e49e5523a..bd3ed25a8 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -85,8 +85,13 @@ CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn)
CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn, const char* pszCommand, unsigned int nMessageSizeIn)
{
memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE);
- memset(pchCommand, 0, sizeof(pchCommand));
- strncpy(pchCommand, pszCommand, COMMAND_SIZE);
+
+ // Copy the command name, zero-padding to COMMAND_SIZE bytes
+ size_t i = 0;
+ for (; i < COMMAND_SIZE && pszCommand[i] != 0; ++i) pchCommand[i] = pszCommand[i];
+ assert(pszCommand[i] == 0); // Assert that the command name passed in is not longer than COMMAND_SIZE
+ for (; i < COMMAND_SIZE; ++i) pchCommand[i] = 0;
+
nMessageSize = nMessageSizeIn;
memset(pchChecksum, 0, CHECKSUM_SIZE);
}