chiark / gitweb /
Makefiles: Use Final.sd.mk to implementing RECHECK_RM
[secnet.git] / conffile.fl
index 66caa1f04cb9d789aa3f499cc28fbf948ff52dd3..6b0259cdeccb58f07eaa4959ffb9e41b757aa033 100644 (file)
@@ -1,7 +1,32 @@
+/*
+ * This file is part of secnet.
+ * See README for full list of copyright holders.
+ *
+ * secnet is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * secnet is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * version 3 along with secnet; if not, see
+ * https://www.gnu.org/licenses/gpl.html.
+ */
 /* the "incl" state is used for picking up the name of an include file */
 %x incl
 
+%option nounput
+%option noinput
+%option never-interactive
+%option noyywrap
+
 %{
+#include <assert.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -23,20 +48,20 @@ do{                                                                 \
 #define MAX_INCLUDE_DEPTH 10
 struct include_stack_item {
        YY_BUFFER_STATE bst;
-       uint32_t lineno;
-       string_t file;
+       int lineno;
+       cstring_t file;
 };
 struct include_stack_item include_stack[MAX_INCLUDE_DEPTH];
 int include_stack_ptr=0;
 
-uint32_t config_lineno=0;
-string_t config_file="xxx";
+int config_lineno=0;
+cstring_t config_file="xxx";
 
 static struct p_node *leafnode(uint32_t type)
 {
        struct p_node *r;
 
-       r=safe_malloc(sizeof(*r),"leafnode");
+       NEW(r);
        r->type=type;
        r->loc.file=config_file;
        r->loc.line=config_lineno;
@@ -65,8 +90,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;
 }
 
@@ -92,6 +134,15 @@ include                     BEGIN(incl);
        yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
        BEGIN(INITIAL);
        }
+<incl>\n               { /* include with no filename */
+       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;
+}
+
 <<EOF>>                {
        if (--include_stack_ptr < 0) {
                yyterminate();
@@ -119,4 +170,3 @@ include                     BEGIN(incl);
 
        /* Return all unclaimed single characters to the parser */
 .                      return *yytext;
-