diff options
author | wm4 <wm4@nowhere> | 2015-04-04 00:02:34 +0200 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2015-04-04 01:04:04 +0200 |
commit | 9ea0590371814f8ce1168056ee2fb228d9b30673 (patch) | |
tree | 95594b99ff113646ca01717cde0d2d5450ec46e0 /options/m_config.c | |
parent | bf3e0bc1dad8a51e60494388e3559c9bb5f1d7e5 (diff) | |
download | mpv-9ea0590371814f8ce1168056ee2fb228d9b30673.tar.bz2 mpv-9ea0590371814f8ce1168056ee2fb228d9b30673.tar.xz |
options: rewrite config file parser
The format doesn't change. Some details are different, though. For
example, it will now accept option values with spaces even if they're
not quoted. (I see no reason why the user should be forced to add
quotes.)
The code is now smaller and should be much easier to extend. It also
can load config from in-memory buffers, which might be helpful in the
future.
read_file() should eventually be replaced with stream_read_complete().
But since the latter function may access options under various
circumstances, and also needs access to the mpv_global struct, there
is a separate implementation for now.
Diffstat (limited to 'options/m_config.c')
-rw-r--r-- | options/m_config.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/options/m_config.c b/options/m_config.c index 5925b7a159..f4179e08cf 100644 --- a/options/m_config.c +++ b/options/m_config.c @@ -42,6 +42,8 @@ static const union m_option_value default_value; // Profiles allow to predefine some sets of options that can then // be applied later on with the internal -profile option. #define MAX_PROFILE_DEPTH 20 +// Maximal include depth. +#define MAX_RECURSION_DEPTH 8 struct m_profile { struct m_profile *next; @@ -66,8 +68,14 @@ static int parse_include(struct m_config *config, struct bstr param, bool set, return M_OPT_MISSING_PARAM; if (!set) return 1; + if (config->recursion_depth >= MAX_RECURSION_DEPTH) { + MP_ERR(config, "Maximum 'include' nesting depth exceeded.\n"); + return M_OPT_INVALID; + } char *filename = bstrdup0(NULL, param); + config->recursion_depth += 1; config->includefunc(config->includefunc_ctx, filename, flags); + config->recursion_depth -= 1; talloc_free(filename); return 1; } |