summaryrefslogtreecommitdiffstats
path: root/cfgparser.c
diff options
context:
space:
mode:
authorszabii <szabii@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-19 21:06:56 +0000
committerszabii <szabii@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-03-19 21:06:56 +0000
commitd5b1225aa03ae0111ec3873207b6442d9ffeb23d (patch)
tree40b3f3379261ed35a56ac1042a4f61e401809b2b /cfgparser.c
parent5bb67aab283eca24c4ac21c7460d2ecff923a767 (diff)
downloadmpv-d5b1225aa03ae0111ec3873207b6442d9ffeb23d.tar.bz2
mpv-d5b1225aa03ae0111ec3873207b6442d9ffeb23d.tar.xz
include recursion check
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@167 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'cfgparser.c')
-rw-r--r--cfgparser.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/cfgparser.c b/cfgparser.c
index f9ab1d6115..6580f6a5aa 100644
--- a/cfgparser.c
+++ b/cfgparser.c
@@ -19,6 +19,8 @@
#define COMMAND_LINE 0
#define CONFIG_FILE 1
+#define MAX_RECURSION_DEPTH 10
+
#ifdef DEBUG
#include <assert.h>
#endif
@@ -28,6 +30,7 @@
static struct config *config;
static int nr_options; /* number of options in 'conf' */
static int parser_mode; /* COMMAND_LINE or CONFIG_FILE */
+static int recursion_depth = 0;
static int init_conf(struct config *conf, int mode)
{
@@ -190,7 +193,6 @@ static int read_option(char *opt, char *param)
if (param == NULL)
goto err_missing_param;
if ((((cfg_func_param_t) config[i].p)(config + i, param)) < 0) {
- printf("parser function returned error:\n");
ret = ERR_FUNC_ERR;
goto out;
}
@@ -198,7 +200,6 @@ static int read_option(char *opt, char *param)
break;
case CONF_TYPE_FUNC:
if ((((cfg_func_t) config[i].p)(config + i)) < 0) {
- printf("parser function returned error:\n");
ret = ERR_FUNC_ERR;
goto out;
}
@@ -239,20 +240,29 @@ int parse_config_file(struct config *conf, char *conffile)
#ifdef DEBUG
assert(conffile != NULL);
#endif
+ if (++recursion_depth > MAX_RECURSION_DEPTH) {
+ printf("too deep 'include'. check your configfiles\n");
+ return -1;
+ }
+
printf("Reading config file: %s\n", conffile);
- if (init_conf(conf, CONFIG_FILE) == -1)
- return -1;
+ if (init_conf(conf, CONFIG_FILE) == -1) {
+ ret = -1;
+ goto out;
+ }
if ((line = (char *) malloc(MAX_LINE_LEN)) == NULL) {
perror("parse_config_file: can't get memory for 'line'");
- return -1;
+ ret = -1;
+ goto out;
}
if ((fp = fopen(conffile, "r")) == NULL) {
perror("parse_config_file: can't open filename");
free(line);
- return 0;
+ ret = 0;
+ goto out;
}
while (fgets(line, MAX_LINE_LEN, fp)) {
@@ -357,6 +367,8 @@ int parse_config_file(struct config *conf, char *conffile)
free(line);
fclose(fp);
+out:
+ --recursion_depth;
return ret;
}