Skip to content

Commit

Permalink
bitcoin#14494: Error if # is used in rpcpassword in conf
Browse files Browse the repository at this point in the history
0385109 Add test for rpcpassword hash error (MeshCollider)
13fe258 Error if rpcpassword in conf contains a hash character (MeshCollider)

Pull request description:

  Fixes bitcoin#13143 now bitcoin#13482 was merged

Tree-SHA512: e7d00c8df1657f6b8d0eee1e06b9ce2b1b0a2de487377699382c1b057836e1571dac313ca878b5877c862f0461ba789a50b239d2a9f34accd8a6321f126e3d2a
  • Loading branch information
laanwj authored and christiancfifi committed Aug 29, 2021
1 parent 4ae3653 commit bfd9852
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/util/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -885,8 +885,10 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
std::string::size_type pos;
int linenr = 1;
while (std::getline(stream, str)) {
bool used_hash = false;
if ((pos = str.find('#')) != std::string::npos) {
str = str.substr(0, pos);
used_hash = true;
}
const static std::string pattern = " \t\r\n";
str = TrimString(str, pattern);
Expand All @@ -899,6 +901,10 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
} else if ((pos = str.find('=')) != std::string::npos) {
std::string name = prefix + TrimString(str.substr(0, pos), pattern);
std::string value = TrimString(str.substr(pos + 1), pattern);
if (used_hash && name == "rpcpassword") {
error = strprintf("parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided", linenr);
return false;
}
options.emplace_back(name, value);
} else {
error = strprintf("parse error on line %i: %s", linenr, str);
Expand Down
9 changes: 9 additions & 0 deletions test/functional/feature_config_args.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ def test_config_file_parser(self):
conf.write('nono\n')
self.nodes[0].assert_start_raises_init_error(expected_msg='Error reading configuration file: parse error on line 1: nono, if you intended to specify a negated option, use nono=1 instead')

with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
conf.write('server=1\nrpcuser=someuser\nrpcpassword=some#pass')
self.nodes[0].assert_start_raises_init_error(expected_msg='Error reading configuration file: parse error on line 3, using # in rpcpassword can be ambiguous and should be avoided')

with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
conf.write('testnot.datadir=1\n[testnet]\n')
self.restart_node(0)
self.nodes[0].stop_node(expected_stderr='Warning: Section [testnet] is not recognized.' + os.linesep + 'Warning: Section [testnot] is not recognized.')

with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
conf.write('') # clear

Expand Down

0 comments on commit bfd9852

Please sign in to comment.