Skip to content

Commit fafd43c

Browse files
author
MarcoFalke
committed
test: Reject + sign when parsing regtest deployment params
The + sign does not make sense for times or heights.
1 parent fa123af commit fafd43c

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/chainparams.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& opti
5353
}
5454

5555
const auto value{arg.substr(found + 1)};
56-
int32_t height;
57-
if (!ParseInt32(value, &height) || height < 0 || height >= std::numeric_limits<int>::max()) {
56+
const auto height{ToIntegral<int32_t>(value)};
57+
if (!height || *height < 0 || *height >= std::numeric_limits<int>::max()) {
5858
throw std::runtime_error(strprintf("Invalid height value (%s) for -testactivationheight=name@height.", arg));
5959
}
6060

6161
const auto deployment_name{arg.substr(0, found)};
6262
if (const auto buried_deployment = GetBuriedDeployment(deployment_name)) {
63-
options.activation_heights[*buried_deployment] = height;
63+
options.activation_heights[*buried_deployment] = *height;
6464
} else {
6565
throw std::runtime_error(strprintf("Invalid name (%s) for -testactivationheight=name@height.", arg));
6666
}
@@ -72,16 +72,22 @@ void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& opti
7272
throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end[:min_activation_height]");
7373
}
7474
CChainParams::VersionBitsParameters vbparams{};
75-
if (!ParseInt64(vDeploymentParams[1], &vbparams.start_time)) {
75+
const auto start_time{ToIntegral<int64_t>(vDeploymentParams[1])};
76+
if (!start_time) {
7677
throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
7778
}
78-
if (!ParseInt64(vDeploymentParams[2], &vbparams.timeout)) {
79+
vbparams.start_time = *start_time;
80+
const auto timeout{ToIntegral<int64_t>(vDeploymentParams[2])};
81+
if (!timeout) {
7982
throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
8083
}
84+
vbparams.timeout = *timeout;
8185
if (vDeploymentParams.size() >= 4) {
82-
if (!ParseInt32(vDeploymentParams[3], &vbparams.min_activation_height)) {
86+
const auto min_activation_height{ToIntegral<int64_t>(vDeploymentParams[3])};
87+
if (!min_activation_height) {
8388
throw std::runtime_error(strprintf("Invalid min_activation_height (%s)", vDeploymentParams[3]));
8489
}
90+
vbparams.min_activation_height = *min_activation_height;
8591
} else {
8692
vbparams.min_activation_height = 0;
8793
}

0 commit comments

Comments
 (0)