From fafd43c69192fcb48a9e04d52eeb07fff15655d0 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Thu, 15 May 2025 21:25:10 +0200 Subject: [PATCH] test: Reject + sign when parsing regtest deployment params The + sign does not make sense for times or heights. --- src/chainparams.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 7cf28d69b4..6be2a63f4e 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -53,14 +53,14 @@ void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& opti } const auto value{arg.substr(found + 1)}; - int32_t height; - if (!ParseInt32(value, &height) || height < 0 || height >= std::numeric_limits::max()) { + const auto height{ToIntegral(value)}; + if (!height || *height < 0 || *height >= std::numeric_limits::max()) { throw std::runtime_error(strprintf("Invalid height value (%s) for -testactivationheight=name@height.", arg)); } const auto deployment_name{arg.substr(0, found)}; if (const auto buried_deployment = GetBuriedDeployment(deployment_name)) { - options.activation_heights[*buried_deployment] = height; + options.activation_heights[*buried_deployment] = *height; } else { throw std::runtime_error(strprintf("Invalid name (%s) for -testactivationheight=name@height.", arg)); } @@ -72,16 +72,22 @@ void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& opti throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end[:min_activation_height]"); } CChainParams::VersionBitsParameters vbparams{}; - if (!ParseInt64(vDeploymentParams[1], &vbparams.start_time)) { + const auto start_time{ToIntegral(vDeploymentParams[1])}; + if (!start_time) { throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1])); } - if (!ParseInt64(vDeploymentParams[2], &vbparams.timeout)) { + vbparams.start_time = *start_time; + const auto timeout{ToIntegral(vDeploymentParams[2])}; + if (!timeout) { throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2])); } + vbparams.timeout = *timeout; if (vDeploymentParams.size() >= 4) { - if (!ParseInt32(vDeploymentParams[3], &vbparams.min_activation_height)) { + const auto min_activation_height{ToIntegral(vDeploymentParams[3])}; + if (!min_activation_height) { throw std::runtime_error(strprintf("Invalid min_activation_height (%s)", vDeploymentParams[3])); } + vbparams.min_activation_height = *min_activation_height; } else { vbparams.min_activation_height = 0; }