Patchwork [26/31] petitboot: Zero parser globals before use

login
register
mail settings
Submitter Geoff Levand
Date July 8, 2009, 12:12 a.m.
Message ID <20090708001136.698766969@am.sony.com>
Download mbox | patch
Permalink /patch/29569/
State New
Headers show

Comments

Geoff Levand - July 8, 2009, 12:12 a.m.
Signed-off-by: Geoff Levand <geoffrey.levand@am.sony.com>
---
 discover/kboot-parser.c  |    1 +
 discover/parser-conf.c   |   19 +++++++++++++++++--
 discover/parser-conf.h   |    1 +
 discover/yaboot-parser.c |    1 +
 4 files changed, 20 insertions(+), 2 deletions(-)

Patch

--- a/discover/kboot-parser.c
+++ b/discover/kboot-parser.c
@@ -137,6 +137,7 @@  static int kboot_parse(struct discover_c
 
 	conf->dc = dc;
 	conf->global_options = kboot_global_options,
+	conf_init_global_options(conf);
 	conf->conf_files = kboot_conf_files,
 	conf->process_pair = kboot_process_pair;
 	conf->parser_info = (void *)kboot_ignored_names,
--- a/discover/parser-conf.c
+++ b/discover/parser-conf.c
@@ -121,6 +121,18 @@  int conf_param_in_list(const char *const
 }
 
 /**
+ * conf_init_global_options - Zero the global option table.
+ */
+
+void conf_init_global_options(struct conf_context *conf)
+{
+	int i;
+
+	for (i = 0; conf->global_options[i].name; i++)
+		conf->global_options[i].value = NULL;
+}
+
+/**
  * conf_set_global_option - Set a value in the global option table.
  *
  * Check if an option (name=value) is a global option. If so, store it in
@@ -136,7 +148,7 @@  int conf_set_global_option(struct conf_c
 		if (streq(name, conf->global_options[i].name)) {
 			conf->global_options[i].value
 				= talloc_strdup(conf, value);
-			pb_log("%s: %s:%s\n", __func__, name, value);
+			pb_log("%s: @%s@%s@\n", __func__, name, value);
 			return 1;
 		}
 	}
@@ -158,8 +170,11 @@  const char *conf_get_global_option(struc
 	int i;
 
 	for (i = 0; conf->global_options[i].name ;i++)
-		if (streq(name, conf->global_options[i].name))
+		if (streq(name, conf->global_options[i].name)) {
+			pb_log("%s: @%s@%s@\n", __func__, name,
+				conf->global_options[i].value);
 			return conf->global_options[i].value;
+		}
 
 	assert(0 && "unknown global name");
 	return NULL;
--- a/discover/parser-conf.h
+++ b/discover/parser-conf.h
@@ -41,6 +41,7 @@  struct conf_context {
 int conf_parse(struct conf_context *conf);
 char *conf_get_param_pair(char *str, char **name_out, char **value_out,
 		char terminator);
+void conf_init_global_options(struct conf_context *conf);
 const char *conf_get_global_option(struct conf_context *conf,
 	const char *name);
 int conf_set_global_option(struct conf_context *conf, const char *name,
--- a/discover/yaboot-parser.c
+++ b/discover/yaboot-parser.c
@@ -240,6 +240,7 @@  static int yaboot_parse(struct discover_
 
 	conf->dc = dc;
 	conf->global_options = yaboot_global_options,
+	conf_init_global_options(conf);
 	conf->conf_files = yaboot_conf_files,
 	conf->process_pair = yaboot_process_pair;
 	conf->finish = yaboot_finish;