Better fix for previous debian bug
authorAlan T. DeKok <aland@freeradius.org>
Mon, 28 Nov 2011 12:44:46 +0000 (13:44 +0100)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 28 Nov 2011 12:46:30 +0000 (13:46 +0100)
src/main/conffile.c

index 29ad97b..531ea9f 100644 (file)
@@ -1085,6 +1085,46 @@ int cf_item_parse(CONF_SECTION *cs, const char *name,
 static const char *parse_spaces = "                                                                                                                                                                                                                                                                ";
 
 /*
+ *     A copy of cf_section_parse that initializes pointers before
+ *     parsing them.
+ */
+static void cf_section_parse_init(CONF_SECTION *cs, void *base,
+                                 const CONF_PARSER *variables)
+{
+       int i;
+       void *data;
+
+       for (i = 0; variables[i].name != NULL; i++) {
+               if (variables[i].type == PW_TYPE_SUBSECTION) {
+                       CONF_SECTION *subcs;
+                       subcs = cf_section_sub_find(cs, variables[i].name);
+                       if (!subcs) continue;
+
+                       if (!variables[i].dflt) continue;
+
+                       cf_section_parse_init(subcs, base,
+                                             (const CONF_PARSER *) variables[i].dflt);
+                       continue;
+               }
+
+               if ((variables[i].type != PW_TYPE_STRING_PTR) &&
+                   (variables[i].type != PW_TYPE_FILENAME)) {
+                       continue;
+               }
+
+               if (variables[i].data) {
+                       data = variables[i].data; /* prefer this. */
+               } else if (base) {
+                       data = ((char *)base) + variables[i].offset;
+               } else {
+                       continue;
+               }
+
+               *(char **) data = NULL;
+       } /* for all variables in the configuration section */
+}
+
+/*
  *     Parse a configuration section into user-supplied variables.
  */
 int cf_section_parse(CONF_SECTION *cs, void *base,
@@ -1103,6 +1143,8 @@ int cf_section_parse(CONF_SECTION *cs, void *base,
                       cs->name1, cs->name2);
        }
 
+       cf_section_parse_init(cs, base, variables);
+
        /*
         *      Handle the known configuration parameters.
         */
@@ -1144,11 +1186,6 @@ int cf_section_parse(CONF_SECTION *cs, void *base,
                        goto error;
                }
 
-               if ((variables[i].type == PW_TYPE_STRING_PTR) ||
-                   (variables[i].type == PW_TYPE_FILENAME)) {
-                       *(char **) data = NULL;
-               }
-
                /*
                 *      Parse the pair we found, or a default value.
                 */