Carpet

Carpet

2M Downloads

When using the `/carpet setDefault` command, the input rule value is written to the conf file before being validated

Fallen-Breath opened this issue ยท 0 comments

commented

carpet.api.settings.SettingsManager#setDefault

// stores different defaults in the file
private int setDefault(CommandSourceStack source, CarpetRule<?> rule, String stringValue)
{
if (locked()) return 0;
if (!rules.containsKey(rule.name())) return 0;
ConfigReadResult conf = readSettingsFromConf(getFile());
conf.ruleMap().put(rule.name(), stringValue);
writeSettingsToConf(conf); // this may feels weird, but if conf
// is locked, it will never reach this point.
try {
rule.set(source, stringValue);
Messenger.m(source ,"gi "+String.format(tr(TranslationKeys.DEFAULT_SET), RuleHelper.translatedName(rule), stringValue));
} catch (InvalidRuleValueException e) {
e.notifySource(rule.name(), source);
}
return 1;
}

As described in the title, the conf file writing (line 699) code happens before the rule value validation (line 702). As a result, invalid rule might be written to the config file, causing unexpected issues on next world loading

This issues affects all existing fabric-carpet versions. It was probrably introduced from the carpetmod 1.12 age