Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13115249
D11788.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D11788.diff
View Options
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -3464,6 +3464,9 @@
uint64_t nExtraEntropy = 1;
vRecv >> nVersion >> nServiceInt >> nTime >> addrMe;
+ if (nTime < 0) {
+ nTime = 0;
+ }
nServices = ServiceFlags(nServiceInt);
if (!pfrom.IsInboundConn()) {
m_connman.SetServices(pfrom.addr, nServices);
diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp
--- a/src/rpc/misc.cpp
+++ b/src/rpc/misc.cpp
@@ -445,9 +445,8 @@
"Set the local time to given timestamp (-regtest only)\n",
{
{"timestamp", RPCArg::Type::NUM, RPCArg::Optional::NO,
- UNIX_EPOCH_TIME +
- "\n"
- " Pass 0 to go back to using the system time."},
+ UNIX_EPOCH_TIME + "\n"
+ "Pass 0 to go back to using the system time."},
},
RPCResult{RPCResult::Type::NONE, "", ""},
RPCExamples{""},
@@ -466,10 +465,11 @@
LOCK(cs_main);
RPCTypeCheck(request.params, {UniValue::VNUM});
- int64_t time = request.params[0].get_int64();
+ const int64_t time{request.params[0].get_int64()};
if (time < 0) {
- throw JSONRPCError(RPC_INVALID_PARAMETER,
- "Timestamp must be 0 or greater");
+ throw JSONRPCError(
+ RPC_INVALID_PARAMETER,
+ strprintf("Mocktime can not be negative: %s.", time));
}
SetMockTime(time);
auto node_context = util::AnyPtr<NodeContext>(request.context);
diff --git a/src/util/time.cpp b/src/util/time.cpp
--- a/src/util/time.cpp
+++ b/src/util/time.cpp
@@ -3,12 +3,14 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+#include <util/time.h>
+
#if defined(HAVE_CONFIG_H)
#include <config/bitcoin-config.h>
#endif
#include <compat.h>
-#include <util/time.h>
+#include <util/check.h>
#include <boost/date_time/posix_time/posix_time.hpp>
@@ -22,7 +24,7 @@
std::this_thread::sleep_for(n);
}
-//! For unit testing
+//! For testing
static std::atomic<int64_t> nMockTime(0);
bool ChronoSanityCheck() {
@@ -90,7 +92,7 @@
}
void SetMockTime(int64_t nMockTimeIn) {
- assert(nMockTimeIn >= 0);
+ Assert(nMockTimeIn >= 0);
nMockTime.store(nMockTimeIn, std::memory_order_relaxed);
}
diff --git a/test/functional/abc_rpc_mocktime.py b/test/functional/abc_rpc_mocktime.py
--- a/test/functional/abc_rpc_mocktime.py
+++ b/test/functional/abc_rpc_mocktime.py
@@ -18,10 +18,11 @@
def run_test(self):
self.nodes[0].setmocktime(9223372036854775807)
self.nodes[0].setmocktime(0)
- assert_raises_rpc_error(-8, "Timestamp must be 0 or greater",
+ assert_raises_rpc_error(-8, "Mocktime can not be negative: -1.",
self.nodes[0].setmocktime, -1)
- assert_raises_rpc_error(-8, "Timestamp must be 0 or greater",
- self.nodes[0].setmocktime, -9223372036854775808)
+ assert_raises_rpc_error(
+ -8, "Mocktime can not be negative: -9223372036854775808.",
+ self.nodes[0].setmocktime, -9223372036854775808)
if __name__ == '__main__':
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Mar 1, 10:29 (11 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5182757
Default Alt Text
D11788.diff (3 KB)
Attached To
D11788: Avoid UBSan warning in ProcessMessage(...) and disallow negative mocktime
Event Timeline
Log In to Comment