# HG changeset patch # User szabii # Date 985036016 0 # Node ID 6b79d801e1835a9f350bc2078f5eed5e878b359b # Parent 5ba7d108d6599a6375fe07ab988f119caaa9b238 include recursion check diff -r 5ba7d108d659 -r 6b79d801e183 cfgparser.c --- a/cfgparser.c Mon Mar 19 20:43:12 2001 +0000 +++ b/cfgparser.c Mon Mar 19 21:06:56 2001 +0000 @@ -19,6 +19,8 @@ #define COMMAND_LINE 0 #define CONFIG_FILE 1 +#define MAX_RECURSION_DEPTH 10 + #ifdef DEBUG #include #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 @@ 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 @@ 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 @@ #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 @@ free(line); fclose(fp); +out: + --recursion_depth; return ret; }