Skip to content

Commit 90c0b6a

Browse files
committed
Merge #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 #13143 now #13482 was merged Tree-SHA512: e7d00c8df1657f6b8d0eee1e06b9ce2b1b0a2de487377699382c1b057836e1571dac313ca878b5877c862f0461ba789a50b239d2a9f34accd8a6321f126e3d2a
2 parents 5cdfd72 + 0385109 commit 90c0b6a

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/util/system.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,10 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
826826
std::string::size_type pos;
827827
int linenr = 1;
828828
while (std::getline(stream, str)) {
829+
bool used_hash = false;
829830
if ((pos = str.find('#')) != std::string::npos) {
830831
str = str.substr(0, pos);
832+
used_hash = true;
831833
}
832834
const static std::string pattern = " \t\r\n";
833835
str = TrimString(str, pattern);
@@ -840,6 +842,10 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
840842
} else if ((pos = str.find('=')) != std::string::npos) {
841843
std::string name = prefix + TrimString(str.substr(0, pos), pattern);
842844
std::string value = TrimString(str.substr(pos + 1), pattern);
845+
if (used_hash && name == "rpcpassword") {
846+
error = strprintf("parse error on line %i, using # in rpcpassword can be ambiguous and should be avoided", linenr);
847+
return false;
848+
}
843849
options.emplace_back(name, value);
844850
} else {
845851
error = strprintf("parse error on line %i: %s", linenr, str);

test/functional/feature_config_args.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ def test_config_file_parser(self):
2929
conf.write('nono\n')
3030
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')
3131

32+
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
33+
conf.write('server=1\nrpcuser=someuser\nrpcpassword=some#pass')
34+
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')
35+
3236
with open(inc_conf_file_path, 'w', encoding='utf-8') as conf:
3337
conf.write('') # clear
3438

0 commit comments

Comments
 (0)