X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=conffile.c;h=5cce211415921556a5c384817d1278d9eb9dc158;hp=db7c58e31b447beb07d89dc1716ae2fd0ad38203;hb=19a171f1601ef89d9b38bd7628b14d64962ab9e1;hpb=27f5042b0435d26ae98b22f8e42115e44afe53bc diff --git a/conffile.c b/conffile.c index db7c58e..5cce211 100644 --- a/conffile.c +++ b/conffile.c @@ -3,6 +3,8 @@ /* #define DUMP_PARSE_TREE */ #include "secnet.h" +#include +#include #include #include #include "conffile.h" @@ -33,7 +35,7 @@ struct dict { struct dict *parent; struct searchlist *search; struct entry *entries; - uint32_t size; + int32_t size; }; static struct atomlist *atoms=NULL; @@ -171,9 +173,9 @@ static string_t ntype(uint32_t type) return "**unknown**"; } -static void ptree_indent(uint32_t amount) +static void ptree_indent(int amount) { - uint32_t i; + int i; for (i=0; itype),n->loc.file,n->loc.line); ptree_indent(d); printf(" |-"); ptree_dump(n->l, d+1); @@ -558,11 +561,11 @@ list_t *list_new(void) return NULL; } -uint32_t list_length(list_t *a) +int32_t list_length(list_t *a) { - uint32_t l=0; + int32_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; } @@ -605,7 +608,7 @@ list_t *list_append(list_t *list, item_t *item) return list_append_list(list,l); } -item_t *list_elem(list_t *l, uint32_t index) +item_t *list_elem(list_t *l, int32_t index) { if (!l) return NULL; if (index==0) return l->item; @@ -685,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; } @@ -700,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; }