chiark / gitweb /
fragmentation: Rename "frag_off" field to "frag"
[secnet.git] / conffile.fl
index 1747be26fb321407edeb44ed124c644c13d80ee7..7228c9e8fa6cd672ea5a3ac480d8328fc161cede 100644 (file)
@@ -6,6 +6,8 @@
 %option never-interactive
 
 %{
+#include <assert.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -27,13 +29,13 @@ do{                                                                 \
 #define MAX_INCLUDE_DEPTH 10
 struct include_stack_item {
        YY_BUFFER_STATE bst;
-       uint32_t lineno;
+       int lineno;
        cstring_t file;
 };
 struct include_stack_item include_stack[MAX_INCLUDE_DEPTH];
 int include_stack_ptr=0;
 
-uint32_t config_lineno=0;
+int config_lineno=0;
 cstring_t config_file="xxx";
 
 static struct p_node *leafnode(uint32_t type)
@@ -69,8 +71,25 @@ static struct p_node *stringnode(string_t string)
 static struct p_node *numnode(string_t number)
 {
        struct p_node *r;
+       unsigned long n;
        r=leafnode(T_NUMBER);
-       r->data.number=atoi(number);
+       errno = 0;
+       n = strtoul(number, NULL, 10);
+       /* The caller is expected to only give us [0-9]+,
+        * so we skip some of the usual syntax checking. */
+       r->data.number=n;
+       /* Give a consistent error message for any kind of
+        * out-of-range condition */
+       if(errno == ERANGE || n != r->data.number) {
+           Message(M_FATAL,"config file %s line %d: '%s' is too big\n",
+                   config_file, config_lineno, number);
+           exit(1);
+       }
+       if(errno) {
+           Message(M_FATAL,"config file %s line %d: '%s': %s\n",
+                   config_file, config_lineno, number, strerror(errno));
+           exit(1);
+       }
        return r;
 }
 
@@ -100,6 +119,7 @@ include                     BEGIN(incl);
        Message(M_FATAL,"config file %s line %d: %s\n",config_file,
                config_lineno,"``include'' requires a filename");
        BEGIN(INITIAL);
+       assert(config_lineno < INT_MAX);
        ++config_lineno;
        ++yynerrs;
 }