Page MenuHomeWildfire Games

Check for invalid config values
AbandonedPublic

Authored by Dariost on Apr 14 2017, 3:22 PM.

Details

Reviewers
vladislavbelov
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Summary

This patch adds a check for invalid config values and set them to a default value in case they're invalid

Test Plan

Try to set invalid values in che *.cfg files or passing them via cli and check that they're ignored and a default value is used

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

elexis added a subscriber: elexis.Apr 14 2017, 3:51 PM

We should have a better system for config values in the first place.
We have some sanitization and type checks in options.js / `options.json', but that doesn't help with people editing config files.
Ideally we had some manifest that states which config values are allowed to be read, which defaults they have, which value types can bet set and which value range is allowed.
We could easily name a bunch of more checks that could be added, but adding these few checks wouldn't hurt I guess.

vladislavbelov requested changes to this revision.Apr 14 2017, 4:07 PM
vladislavbelov added a subscriber: vladislavbelov.

There is still a problem:

let scale = +Engine.ConfigDB_GetValue("user", "gui.scale");

You get the config value, but in C++ you've changed only global variables and this line still will return an invalid value, so config data should be updated somehow too.

This revision now requires changes to proceed.Apr 14 2017, 4:07 PM
Dariost updated this revision to Diff 1244.Apr 14 2017, 5:07 PM
Dariost edited edge metadata.

I had to add another level to CConfigDB to overcome what @vladislavbelov pointed out. Now the sanitized values should be propagated to JavaScript.

vladislavbelov requested changes to this revision.Apr 16 2017, 9:41 PM
vladislavbelov added inline comments.
source/ps/ConfigDB.h
44

What's a reason of adding this?

111

As you can see above, people prefer to use "classic" names for types, SetValueBool/FromInt, I don't really mind, if leave as is, but to be convinced, I want to someone take a look at it too.

source/ps/GameSetup/Config.cpp
193

ps/VideoMode.cpp has defined default values and methods for getting default desktop resolution, couldn't we use it instead of this hard-coded values?

This revision now requires changes to proceed.Apr 16 2017, 9:41 PM
Dariost updated this revision to Diff 1290.Apr 16 2017, 10:16 PM
Dariost edited edge metadata.
Dariost marked 2 inline comments as done.
Dariost added inline comments.Apr 16 2017, 10:18 PM
source/ps/ConfigDB.h
44

Before adding this the most important CFG was CFG_COMMAND, but the config variables checking is more important than CLI arguments (and also setting them as CFG_COMMAND wouldn't make sense), so I added CFG_SANITIZE

In D330#12963, @elexis wrote:

We should have a better system for config values in the first place.
We have some sanitization and type checks in options.js / `options.json', but that doesn't help with people editing config files.

Nobody should need to edit a config file by hand (that they still have to do so in a few cases just shows that the options screen is incomplete). If they still want to do that they will have to take care, no hand holding.

Ideally we had some manifest that states which config values are allowed to be read, which defaults they have, which value types can bet set and which value range is allowed.

That'd be nice, but we do have that in the options screen which should be good enough. (And I'd prefer not having config files in XML.)

For the overall patch: No to the ConfigDB changes (apart from missing locking and possibly namespace checks). You should sanitize values before they are stored there, not figure out what is valid afterwards.

Dariost abandoned this revision.Apr 18 2017, 11:24 AM
In D330#13745, @leper wrote:

Nobody should need to edit a config file by hand (that they still have to do so in a few cases just shows that the options screen is incomplete). If they still want to do that they will have to take care, no hand holding.

Then I think it's better to abandon this patch since this is only meant for people who manually edit che config file.