X-Git-Url: https://jxself.org/git/?p=carl9170fw.git;a=blobdiff_plain;f=config%2Fpreprocess.c;h=b028a48b0e761f491f90e29df43b6975f5a0a757;hp=0574039238c65cf1df6bb1dba86b9fff8c989375;hb=342b243d70ea8bd00733d288f08fa89cf44a2773;hpb=6598140e430d622be926aed43ec19fec8326cd11 diff --git a/config/preprocess.c b/config/preprocess.c index 0574039..b028a48 100644 --- a/config/preprocess.c +++ b/config/preprocess.c @@ -156,7 +156,7 @@ static char *do_shell(int argc, char *argv[]) nread--; /* remove trailing new lines */ - while (buf[nread - 1] == '\n') + while (nread > 0 && buf[nread - 1] == '\n') nread--; buf[nread] = 0; @@ -229,6 +229,7 @@ struct variable { char *name; char *value; enum variable_flavor flavor; + int exp_count; struct list_head node; }; @@ -253,11 +254,22 @@ static char *variable_expand(const char *name, int argc, char *argv[]) if (!v) return NULL; + if (argc == 0 && v->exp_count) + pperror("Recursive variable '%s' references itself (eventually)", + name); + + if (v->exp_count > 1000) + pperror("Too deep recursive expansion"); + + v->exp_count++; + if (v->flavor == VAR_RECURSIVE) res = expand_string_with_args(v->value, argc, argv); else res = xstrdup(v->value); + v->exp_count--; + return res; } @@ -284,6 +296,7 @@ void variable_add(const char *name, const char *value, v = xmalloc(sizeof(*v)); v->name = xstrdup(name); + v->exp_count = 0; list_add_tail(&v->node, &variable_list); } @@ -542,8 +555,7 @@ char *expand_string(const char *in) static bool is_end_of_token(char c) { - /* Why are '.' and '/' valid characters for symbols? */ - return !(isalnum(c) || c == '_' || c == '-' || c == '.' || c == '/'); + return !(isalnum(c) || c == '_' || c == '-'); } /*