From: Justin Pettit Date: Sat, 1 Aug 2009 07:58:31 +0000 (-0700) Subject: cfg: Terminate cfg to prevent crashes X-Git-Tag: v0.90.5~80 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=590ab3cc649ca3ecc56e6c5057e7e4e24874a625;p=sliver-openvswitch.git 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 --- diff --git a/lib/cfg.c b/lib/cfg.c index 433d7a0fa..225827ef5 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 42345f86b..e159244eb 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);