diff options
author | Justin Pettit <jpettit@nicira.com> | 2009-08-01 00:58:31 -0700 |
---|---|---|
committer | Justin Pettit <jpettit@nicira.com> | 2009-08-01 00:58:31 -0700 |
commit | 590ab3cc649ca3ecc56e6c5057e7e4e24874a625 (patch) | |
tree | bb2b773273b7f7c96510b5e7216e3cbb30c33d41 | |
parent | 85c74638ed99b77d6894385c3dce0175c4b4baa4 (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.c | 7 | ||||
-rw-r--r-- | lib/cfg.h | 1 |
2 files changed, 8 insertions, 0 deletions
@@ -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; } @@ -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); |