4 minor findings · 7 suggestions
Earlier concerns neither republished nor resolved: 1 minor finding · 1 suggestion. See the Run archive for their assessments.
Findings
[minor] · System fuzz target can abort on typed -chain or re-registered -help-debug
Typed or re-registered arguments can make the harness's final getters throw uncaught logic_error, causing a fuzz-harness crash rather than exposing a product bug.
Location: src/test/fuzz/system.cpp:40 (head).
Details and suggested fix
Two reachable sequences can trigger the crash. The AddArg branch can register -chain with ALLOW_INT, ALLOW_BOOL, or ALLOW_STRING | ALLOW_LIST; the final GetChainTypeString() call then reaches GetArg("-chain"), whose CheckArgFlags() throws std::logic_error. The harness catches only std::runtime_error there. Separately, ClearArgs() removes the -help-debug registration, after which the AddArg branch can register that name with, for example, ALLOW_INT. The unguarded GetHelpMessage() call then throws through GetBoolArg("-help-debug", false). Neither getter checked flags before this change. After each ClearArgs(), re-register -help-debug and -chain with ALLOW_ANY and skip those names in the AddArg branch, or catch exceptions around both calls as the harness does for direct getters. Update the comment to name GetHelpMessage(): HelpRequested() only calls IsArgSet(), which does not check flags.
[minor] · SoftSetArg can report success while storing unreadable values for typed settings
For typed integer or boolean settings, SoftSetArg skips the flag check, so it can return true even though a getter reads the value as unset.
Location: src/common/args.cpp:723 (head).
Details and suggested fix
ForceSetArg() and SoftSetBoolArg() check the registered flags, but SoftSetArg() writes its string to forced_settings without checking them. For an ALLOW_INT setting, SoftSetArg("-foo", "42") returns true, but GetIntArg("-foo") returns nullopt because typed ConvertToInt() does not parse strings. A defaulted getter then silently returns its default. SoftSetArg("-flag", "1") has the same problem for an ALLOW_BOOL setting. The fuzz catch expects a "Can't call ForceSetArg" error that SoftSetArg() cannot throw, so it is dead code. Parse the value with InterpretValue() using the registered flags, or at minimum apply the same CheckArgFlags() check as ForceSetArg(). No current production caller uses SoftSetArg() with a typed setting, so production impact is unconfirmed.
[minor] · ALLOW_BOOL | ALLOW_LIST loses explicit false values and earlier entries
AddArg accepts this flag combination, but an explicit 0 becomes the false value that resets the settings list, discarding it and earlier entries.
Location: src/common/args.cpp:168 (head).
Details and suggested fix
For an ALLOW_BOOL setting, InterpretValue() stores -flag=0 as JSON false. The settings merge treats any false as a list reset: SettingsSpan::begin() skips everything through the last false. Thus -flag=1 -flag=0 with ALLOW_BOOL | ALLOW_LIST parses without error, but GetSettingsList("-flag") returns an empty list. DISALLOW_NEGATION does not help because neither argument is negated. No getter supports this combination: GetBoolArg() forbids ALLOW_LIST, while GetArgs() requires ALLOW_STRING. Reject ALLOW_BOOL | ALLOW_LIST in AddArg() and add a test until explicit false can be distinguished from negation. No checked-in caller registers a boolean list, so this affects only future use of the combination.
[minor] · Dashless getter names bypass typed checks and conversions
Because getters accept both foo and -foo but flag lookup matches only -foo, the same typed setting can return different values depending on how its name is spelled.
Location: src/common/args.cpp:389 (head).
Details and suggested fix
CheckArgFlags() looks up the name exactly as passed, and GetArgFlags_() matches registered names such as -foo exactly. But GetSetting() strips a leading dash, so getters also accept foo. A dashless call on a typed setting finds no flags, treats the setting as untyped, and uses legacy coercions. For example, with an ALLOW_BOOL setting parsed from -foo=, GetBoolArg("-foo", false) returns false, while GetBoolArg("foo", false) returns true through InterpretBool(""). A mismatched call such as GetIntArg("foo") on an ALLOW_BOOL setting also skips the intended logic_error. Normalize the name to '-' + SettingName(name) before flag lookup, and cover both spellings in the typed tests. Dashless getter calls appear in getarg_tests, and no production setting uses type flags yet, so production impact is unconfirmed.
Optional improvements
[suggestion] · Flag documentation recommends getter patterns that reject valid flag combinations
Following the documented patterns can cause logic_error or register a list setting that no getter can read.
Location: src/common/args.h:157 (head).
Details and suggested fix
The documentation says to enforce single-value behavior by calling GetArgs() and raising an error when it returns more than one value. It also recommends adding ALLOW_LIST when all values are needed. But GetArgs() now requires ALLOW_STRING | ALLOW_LIST, so the first pattern throws logic_error for ALLOW_INT, ALLOW_BOOL, or scalar ALLOW_STRING settings. Following the second pattern for integers gives ALLOW_INT | ALLOW_LIST, which AddArg() accepts but no helper can read: GetArgs() requires ALLOW_STRING, and GetIntArg() forbids ALLOW_LIST. The same documentation says settings can be specified multiple times, but ReadConfigStream() now rejects repeated typed non-list settings within one config section. Update the documentation to direct readers to GetSettingsList() for inspecting multiple values and explain the config-file restriction. Also either allow GetArgs() to accept ALLOW_INT | ALLOW_LIST or reject that combination at registration.
[suggestion] · Narrow typed integer getters throw a generic out-of-range error
An out-of-range value accepted during startup can later throw a generic exception rather than returning nullopt as documented.
Location: src/common/args.cpp:207 (head).
Details and suggested fix
For ALLOW_INT settings, InterpretValue() accepts any int64_t and stores a JSON number. ConvertToInt<Int>() calls value.getInt<Int>(), which throws std::runtime_error("JSON integer out of range") when the value does not fit Int. For example, GetArg<uint16_t>("-foo") with -foo=70000 throws, as does GetArg<int> with a value above INT_MAX. The error names neither the setting nor its source. Untyped settings instead saturate through LocaleIndependentAtoi. The header says typed getters act like std::get_if<T>() and return null when the requested type is unavailable. In the typed branch, range-check and return nullopt as documented, or throw an error naming the option and allowed range. Add CheckValueTest cases using narrow getters. This matters only once a setting read through a narrower GetArg<Int> is migrated to ALLOW_INT.
[suggestion] · AddArg leaves rejected registrations installed after a flag check throws
Flag combinations are checked after insertion, so a caught logic_error leaves the rejected flags registered and prevents a corrected retry.
Location: src/common/args.cpp:780 (head).
Details and suggested fix
AddArg() inserts the argument into m_available_args, and into m_network_only_args for NETWORK_ONLY, before checking flag combinations. If a check throws, the state is not rolled back. GetArgFlags() then returns the rejected flags, and retrying with corrected flags trips the duplicate-registration assertion. Move the combination checks before emplace so failure leaves no partial state. No caller currently catches and retries; invalid flags are programming errors, and util_CheckBadFlagCombinations uses a fresh name for each case.
[suggestion] · Typed GetArg treats JSON true as unset despite the documented bool-to-string widening
An ALLOW_STRING setting with a stored value of true reads as unset, so the defaulted getter silently returns its default.
Location: src/common/args.cpp:194 (head).
Details and suggested fix
The header documents widening conversions of bool -> int -> string. ConvertToInt() widens both true and false, but for typed settings ConvertToString() maps only false to "" and returns nullopt for true. Thus an ALLOW_STRING setting whose settings.json value is true reads as unset, and GetArg(name, default) silently returns the default. The untyped path returns "1". Command-line and config input cannot produce true for an ALLOW_STRING setting, so this affects only settings.json or forceSetting values. Convert typed true to "1", or narrow the documented widening statement.
[suggestion] · Duplicate-value errors can span included files and omit the file path
Splitting a typed option across includeconf files can produce an error that wrongly says the duplicate is within one file and does not identify a file.
Location: src/common/config.cpp:104 (head).
Details and suggested fix
The duplicate check reads the accumulated ro_config. ReadConfigFiles() adds values from the main config and each includeconf file without resetting it. Consequently, foo=1 in bitcoin.conf and foo=2 in an included file fail with "Multiple values specified for -foo in same section of config file." even though neither file repeats the key. The message also omits the file path available in ReadConfigStream(). Rejecting cross-file duplicates may be intended because otherwise the later value would be silently ignored. Either way, make the message describe the check and name the file. If only within-file duplicates should fail, make the check stream-local. No production option uses type flags yet.
[suggestion] · Example narrows a validated int64_t without checking the upper bound
The reference example accepts -bytespersigop=4294967296 on a system with 32-bit int and stores 0 instead of rejecting it.
Location: src/test/argsman_tests.cpp:112 (head).
Details and suggested fix
ReadOptions() is the documented usage example. It checks the int64_t from GetIntArg("-bytespersigop") only for values below 1, then assigns it to int bytes_per_sigop. With 32-bit int, -bytespersigop=4294967296 passes the check and becomes 0. Check against std::numeric_limits<int>::max() before assigning, and add a boundary test, so the example shows complete range validation.
[suggestion] · Parsing-only test constructs an unused 100-block chain
util_CheckBoolStringsNotSpecial uses a fixture that mines 100 blocks even though the test only exercises a local args manager.
Location: src/test/argsman_tests.cpp:554 (head).
Details and suggested fix
util_CheckBoolStringsNotSpecial uses CheckValueTest, which inherits from TestChain100Setup; its constructor mines and processes 100 blocks. CheckValue() only uses a local TestArgsManager, so the chain setup is unnecessary. Make CheckValueTest derive from BasicTestingSetup to keep the assertions unchanged and avoid this setup cost in both the new test and the existing util_CheckValue.
Earlier concerns
Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.
- [minor]: SoftSetBoolArg changes untyped false values into negations
- [suggestion]: Clarify whether type flags validate settings.json