[ovs-discuss] [PATCH] cfg: Terminate cfg to prevent crashes

Justin Pettit jpettit at nicira.com
Sat Aug 1 08:07:59 UTC 2009


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
---
 lib/cfg.c |    7 +++++++
 lib/cfg.h |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/lib/cfg.c b/lib/cfg.c
index 433d7a0..225827e 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 42345f8..e159244 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);
-- 
1.5.5





More information about the discuss mailing list