From a395e319eea1cf52a6ed4a07bacd91df9c9a5c79 Mon Sep 17 00:00:00 2001 From: freetrader Date: Mon, 4 Sep 2023 14:10:01 +0200 Subject: [PATCH] Fix comparing wrong blocksize parameter variable Compiler warning was unfortunately missed, but this seems a clear case of comparing the wrong variable, resulting in a condition which can never be true (unsigned < 0). A functional test is adapted to trigger the invalid value case for `blockmaxsize` and check that the message is produced. Test Plan --------- - `ninja all check-all` --- src/init.cpp | 2 +- test/functional/abc-cmdline.py | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 254aeaa9a0..92373d2268 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1739,7 +1739,7 @@ bool AppInitParameterInteraction(Config &config) { return InitError(_("Cannot set both -blockmaxsize and -percentblockmaxsize")); } else if (has_bms && !has_pbms) { const int64_t nProposedMaxGeneratedBlockSize = gArgs.GetArg("-blockmaxsize", int64_t{-1}); - if (nProposedExcessiveBlockSize < 0) { + if (nProposedMaxGeneratedBlockSize < 0) { return InitError(_("Invalid value specified for -blockmaxsize")); } // Check blockmaxsize does not exceed maximum accepted block size. diff --git a/test/functional/abc-cmdline.py b/test/functional/abc-cmdline.py index 7b78b79057..9773601297 100755 --- a/test/functional/abc-cmdline.py +++ b/test/functional/abc-cmdline.py @@ -20,6 +20,8 @@ MAX_GENERATED_BLOCK_SIZE_ERROR = ( 'Max generated block size (blockmaxsize) cannot exceed the excessive block size (excessiveblocksize)') +INVALID_GENERATED_BLOCK_SIZE_ERROR = ( + 'Invalid value specified for -blockmaxsize') class ABC_CmdLine_Test (BitcoinTestFramework): @@ -79,6 +81,10 @@ def excessiveblocksize_test(self): self.nodes[0].assert_start_raises_init_error( ['-blockmaxsize=1500000', '-excessiveblocksize=1300000'], 'Error: ' + MAX_GENERATED_BLOCK_SIZE_ERROR) + self.log.info(" Attempt to set invalid blockmaxsize (mining limit)") + self.nodes[0].assert_start_raises_init_error( + ['-blockmaxsize=-1'], 'Error: ' + INVALID_GENERATED_BLOCK_SIZE_ERROR) + # Make sure we leave the test with a node running as this is what thee # framework expects. self.start_node(0, [])