aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Pettit <jpettit@nicira.com>2009-08-01 00:58:31 -0700
committerJustin Pettit <jpettit@nicira.com>2009-08-01 00:58:31 -0700
commit590ab3cc649ca3ecc56e6c5057e7e4e24874a625 (patch)
treebb2b773273b7f7c96510b5e7216e3cbb30c33d41
parent85c74638ed99b77d6894385c3dce0175c4b4baa4 (diff)
cfg: Terminate cfg to prevent crashes
If cfg_* accessor calls were made before cfg_read() was called (or it returned error), they could cause segfault. This checkin terminates the cfg structure in such a way that will prevent these run-time problems. Bug #1693
-rw-r--r--lib/cfg.c7
-rw-r--r--lib/cfg.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/lib/cfg.c b/lib/cfg.c
index 433d7a0f..225827ef 100644
--- a/lib/cfg.c
+++ b/lib/cfg.c
@@ -92,6 +92,12 @@ static bool is_type(const char *s, enum cfg_flags);
#define CC_FILE_NAME CC_ALNUM "._-"
#define CC_KEY CC_ALNUM "._-@$:+"
+void
+cfg_init(void)
+{
+ svec_terminate(&cfg);
+}
+
/* Sets 'file_name' as the configuration file read by cfg_read(). Returns 0 on
* success, otherwise a positive errno value if 'file_name' cannot be opened.
*
@@ -183,6 +189,7 @@ cfg_read(void)
file = fopen(cfg_name, "r");
if (!file) {
VLOG_ERR("failed to open \"%s\": %s", cfg_name, strerror(errno));
+ svec_terminate(&cfg);
return errno;
}
diff --git a/lib/cfg.h b/lib/cfg.h
index 42345f86..e159244e 100644
--- a/lib/cfg.h
+++ b/lib/cfg.h
@@ -26,6 +26,7 @@
struct svec;
struct ofpbuf;
+void cfg_init(void);
int cfg_set_file(const char *file_name);
int cfg_read(void);
int cfg_lock(uint8_t *cookie, int timeout);