]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Conf: Better error message when reading iproute2 config
authorMaria Matejka <mq@ucw.cz>
Tue, 4 Feb 2020 09:34:46 +0000 (10:34 +0100)
committerMaria Matejka <mq@ucw.cz>
Tue, 4 Feb 2020 09:34:46 +0000 (10:34 +0100)
Reported by: Martin Weinelt <martin@darmstadt.freifunk.net>

conf/conf.h
sysdep/unix/main.c

index 21dc3fa1fbecef0e4f9086c172e8e5c6905ff3cc..0dea4f9420552b85398f3d1d1f9c660d753611d5 100644 (file)
@@ -198,11 +198,11 @@ struct symbol *cf_localize_symbol(struct symbol *sym);
  * Result: Pointer to the newly defined symbol. If we are in the top-level
  * scope, it's the same @sym as passed to the function.
  */
-#define cf_define_symbol(sym_, type_, var_, def_) ({ \
-    struct symbol *sym = cf_localize_symbol(sym_); \
-    sym->class = type_; \
-    sym->var_ = def_; \
-    sym; })
+#define cf_define_symbol(osym_, type_, var_, def_) ({ \
+    struct symbol *sym_ = cf_localize_symbol(osym_); \
+    sym_->class = type_; \
+    sym_->var_ = def_; \
+    sym_; })
 
 void cf_push_scope(struct symbol *);
 void cf_pop_scope(void);
index d9d9ad84c4ca3a1e47859b9abbfffcaff2b23998..5209b9b33fb6296dde41521390afab88b9e7fa4f 100644 (file)
@@ -95,11 +95,15 @@ drop_gid(gid_t gid)
 #ifdef PATH_IPROUTE_DIR
 
 static inline void
-add_num_const(char *name, int val)
+add_num_const(char *name, int val, const char *file, const uint line)
 {
   struct f_val *v = cfg_alloc(sizeof(struct f_val));
   *v = (struct f_val) { .type = T_INT, .val.i = val };
-  cf_define_symbol(cf_get_symbol(name), SYM_CONSTANT | T_INT, val, v);
+  struct symbol *sym = cf_get_symbol(name);
+  if (sym->class && (sym->scope == conf_this_scope))
+    cf_error("Error reading value for %s from %s:%d: already defined", name, file, line);
+
+  cf_define_symbol(sym, SYM_CONSTANT | T_INT, val, v);
 }
 
 /* the code of read_iproute_table() is based on
@@ -119,7 +123,7 @@ read_iproute_table(char *file, char *prefix, int max)
   if (!fp)
     return;
 
-  while (fgets(buf, sizeof(buf), fp))
+  for (uint line = 1; fgets(buf, sizeof(buf), fp); line++)
   {
     char *p = buf;
 
@@ -142,7 +146,7 @@ read_iproute_table(char *file, char *prefix, int max)
       if ((*p < 'a' || *p > 'z') && (*p < 'A' || *p > 'Z') && (*p < '0' || *p > '9') && (*p != '_'))
        *p = '_';
 
-    add_num_const(namebuf, val);
+    add_num_const(namebuf, val, file, line);
   }
 
   fclose(fp);