~mdw
/
secnet
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
integer arithmetic types: do not use unsigned for site timeouts etc.
[secnet]
/
conffile.c
diff --git
a/conffile.c
b/conffile.c
index
660606e
..
5cce211
100644
(file)
--- a/
conffile.c
+++ b/
conffile.c
@@
-3,16
+3,16
@@
/* #define DUMP_PARSE_TREE */
#include "secnet.h"
/* #define DUMP_PARSE_TREE */
#include "secnet.h"
+#include <assert.h>
+#include <limits.h>
#include <stdio.h>
#include <string.h>
#include "conffile.h"
#include "conffile_internal.h"
#include <stdio.h>
#include <string.h>
#include "conffile.h"
#include "conffile_internal.h"
+#include "conffile.yy.h"
#include "util.h"
#include "ipaddr.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 {
static struct cloc no_loc={"none",0};
struct atomlist {
@@
-35,7
+35,7
@@
struct dict {
struct dict *parent;
struct searchlist *search;
struct entry *entries;
struct dict *parent;
struct searchlist *search;
struct entry *entries;
-
u
int32_t size;
+ int32_t size;
};
static struct atomlist *atoms=NULL;
};
static struct atomlist *atoms=NULL;
@@
-173,9
+173,9
@@
static string_t ntype(uint32_t type)
return "**unknown**";
}
return "**unknown**";
}
-static void ptree_indent(
uint32_
t amount)
+static void ptree_indent(
in
t amount)
{
{
-
uint32_
t i;
+
in
t i;
for (i=0; i<amount; i++) printf(" . ");
}
for (i=0; i<amount; i++) printf(" . ");
}
@@
-197,6
+197,7
@@
static void ptree_dump(struct p_node *n, uint32_t d)
default: printf("**unknown primitive type**\n"); break;
}
} else {
default: printf("**unknown primitive type**\n"); break;
}
} else {
+ assert(d<INT_MAX);
printf("%s: (%s line %d)\n",ntype(n->type),n->loc.file,n->loc.line);
ptree_indent(d);
printf(" |-"); ptree_dump(n->l, d+1);
printf("%s: (%s line %d)\n",ntype(n->type),n->loc.file,n->loc.line);
ptree_indent(d);
printf(" |-"); ptree_dump(n->l, d+1);
@@
-560,15
+561,15
@@
list_t *list_new(void)
return NULL;
}
return NULL;
}
-
u
int32_t list_length(list_t *a)
+int32_t list_length(list_t *a)
{
{
-
u
int32_t l=0;
+ int32_t l=0;
list_t *i;
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;
}
return l;
}
-list_t *list_copy(list_t *a)
+
static
list_t *list_copy(list_t *a)
{
list_t *r, *i, *b, *l;
{
list_t *r, *i, *b, *l;
@@
-607,7
+608,7
@@
list_t *list_append(list_t *list, item_t *item)
return list_append_list(list,l);
}
return list_append_list(list,l);
}
-item_t *list_elem(list_t *l,
u
int32_t index)
+item_t *list_elem(list_t *l, int32_t index)
{
if (!l) return NULL;
if (index==0) return l->item;
{
if (!l) return NULL;
if (index==0) return l->item;
@@
-687,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 (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;
}
r=i->data.string;
return r;
}
@@
-702,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->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;
}
r=i->data.number;
return r;
}