Skip to content

Commit b9d2e81

Browse files
laanwjchristiancfifi
authored andcommitted
bitcoin#14494: Error if # is used in rpcpassword in conf
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
1 parent 1457eda commit b9d2e81

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/util/system.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -885,8 +885,10 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
885885
std::string::size_type pos;
886886
int linenr = 1;
887887
while (std::getline(stream, str)) {
888+
bool used_hash = false;
888889
if ((pos = str.find('#')) != std::string::npos) {
889890
str = str.substr(0, pos);
891+
used_hash = true;
890892
}
891893
const static std::string pattern = " \t\r\n";
892894
str = TrimString(str, pattern);
@@ -899,6 +901,10 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
899901
} else if ((pos = str.find('=')) != std::string::npos) {
900902
std::string name = prefix + TrimString(str.substr(0, pos), pattern);
901903
std::string value = TrimString(str.substr(pos + 1), pattern);
904+
if (used_hash && name == "rpcpassword") {
905+
error = strprintf("parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided", linenr);
906+
return false;
907+
}
902908
options.emplace_back(name, value);
903909
} else {
904910
error = strprintf("parse error on line %i: %s", linenr, str);

test/functional/feature_config_args.py

100755100644
+9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def test_config_file_parser(self):
3939
conf.write('nono\n')
4040
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')
4141

42+
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
43+
conf.write('server=1\nrpcuser=someuser\nrpcpassword=some#pass')
44+
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')
45+
46+
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
47+
conf.write('testnot.datadir=1\n[testnet]\n')
48+
self.restart_node(0)
49+
self.nodes[0].stop_node(expected_stderr='Warning: Section [testnet] is not recognized.' + os.linesep + 'Warning: Section [testnot] is not recognized.')
50+
4251
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
4352
conf.write('') # clear
4453

0 commit comments

Comments
 (0)