X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=conffile.c;h=565e37ff9b8ed608ea867106aaebc17156d3b8f9;hp=b17517b58092d800da561c44f28420dbcdd54f30;hb=0009e60a914ef5239ba2f8cc19e07ab5368e49b1;hpb=fe5e9cc422cd72526ccfceffbc7e5af8ac83b407 diff --git a/conffile.c b/conffile.c index b17517b..565e37f 100644 --- a/conffile.c +++ b/conffile.c @@ -3,16 +3,16 @@ /* #define DUMP_PARSE_TREE */ #include "secnet.h" +#include +#include #include #include #include "conffile.h" #include "conffile_internal.h" +#include "conffile.yy.h" #include "util.h" #include "ipaddr.h" -/* from modules.c */ -extern void init_builtin_modules(dict_t *dict); - static struct cloc no_loc={"none",0}; struct atomlist { @@ -197,6 +197,7 @@ static void ptree_dump(struct p_node *n, uint32_t d) default: printf("**unknown primitive type**\n"); break; } } else { + assert(dtype),n->loc.file,n->loc.line); ptree_indent(d); printf(" |-"); ptree_dump(n->l, d+1); @@ -466,6 +467,9 @@ static dict_t *process_config(struct p_node *c) context=root; /* Predefined keys for boolean values */ + /* "nowise" and "verily" have the advantage of being the same + length, so they line up nicely... thanks VKC and SGT (who also + point out that "mayhap" is a good "maybe" value as well) */ i=new_item(t_bool,no_loc); i->data.bool=False; false=list_append(NULL,i); @@ -478,12 +482,18 @@ static dict_t *process_config(struct p_node *c) dict_add(root,"no",false); dict_add(root,"No",false); dict_add(root,"NO",false); + dict_add(root,"nowise",false); + dict_add(root,"Nowise",false); + dict_add(root,"NOWISE",false); dict_add(root,"true",true); dict_add(root,"True",true); dict_add(root,"TRUE",true); dict_add(root,"yes",true); dict_add(root,"Yes",true); dict_add(root,"YES",true); + dict_add(root,"verily",true); + dict_add(root,"Verily",true); + dict_add(root,"VERILY",true); add_closure(root,"makelist",makelist); add_closure(root,"readfile",readfile); @@ -555,11 +565,11 @@ uint32_t list_length(list_t *a) { uint32_t l=0; list_t *i; - for (i=a; i; i=i->next) l++; + for (i=a; i; i=i->next) { assert(l < INT_MAX); l++; } return l; } -list_t *list_copy(list_t *a) +static list_t *list_copy(list_t *a) { list_t *r, *i, *b, *l; @@ -619,6 +629,7 @@ void add_closure(dict_t *dict, cstring_t name, apply_fn apply) closure_t *c; c=safe_malloc(sizeof(*c),"add_closure"); c->description=name; + c->type=CL_PURE; c->apply=apply; c->interface=NULL; @@ -677,6 +688,9 @@ string_t dict_read_string(dict_t *dict, cstring_t key, bool_t required, if (i->type!=t_string) { cfgfatal(loc,desc,"\"%s\" must be a string\n",key); } + if (strlen(i->data.string) > INT_MAX/10) { + cfgfatal(loc,desc,"\"%s\" is unreasonably long\n",key); + } r=i->data.string; return r; } @@ -692,6 +706,9 @@ uint32_t dict_read_number(dict_t *dict, cstring_t key, bool_t required, if (i->type!=t_number) { cfgfatal(loc,desc,"\"%s\" must be a number\n",key); } + if (i->data.number >= 0x80000000) { + cfgfatal(loc,desc,"\"%s\" must fit into a 32-bit signed integer\n",key); + } r=i->data.number; return r; }