Skip to content

Commit

Permalink
chain: disallow overwriting settings with null values
Browse files Browse the repository at this point in the history
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
  • Loading branch information
ismaelsadeeq and ryanofsky committed Sep 5, 2024
1 parent 3734257 commit 4627174
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -819,18 +819,22 @@ class ChainImpl : public Chain
{
std::optional<interfaces::SettingsAction> action;
args().LockSettings([&](common::Settings& settings) {
auto* ptr_value = common::FindKey(settings.rw_settings, name);
// Create value if it doesn't exist
auto& value = ptr_value ? *ptr_value : settings.rw_settings[name];
action = update_settings_func(value);
if (auto* value = common::FindKey(settings.rw_settings, name)) {
action = update_settings_func(*value);
if (value->isNull()) settings.rw_settings.erase(name);
} else {
UniValue new_value;
action = update_settings_func(new_value);
if (!new_value.isNull()) settings.rw_settings[name] = std::move(new_value);
}
});
if (!action) return false;
// Now dump value to disk if requested
return *action == interfaces::SettingsAction::SKIP_WRITE || args().WriteSettingsFile();
}
bool overwriteRwSetting(const std::string& name, common::SettingsValue value, interfaces::SettingsAction action) override
{
if (value.isNull()) return deleteRwSettings(name, action);
if (value.isNull()) return false; // disallow overwriting with null values.
return updateRwSetting(name, [&](common::SettingsValue& settings) {
settings = std::move(value);
return action;
Expand Down

0 comments on commit 4627174

Please sign in to comment.