From a29ec1f1484902400f08b24ed777ea984923ffea Mon Sep 17 00:00:00 2001 From: Shehjar Tikoo Date: Sun, 24 May 2009 23:05:26 +0000 Subject: booster: Clean-up handling of log/fstab env variables Handle two cases when deciding log/fstab file: 1. It turns out that that strdup or strlen doesnt actually check for NULL before trying to do its thing with the string so it seg-faults on seeing a NULL char pointer. 2. getenv can return an empty string if the env var was exported as: $ export GLUSTEFS_BOOSTER_LOG= Signed-off-by: Anand V. Avati --- booster/src/booster.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'booster') diff --git a/booster/src/booster.c b/booster/src/booster.c index b51cc25cae3..cb35be519d3 100644 --- a/booster/src/booster.c +++ b/booster/src/booster.c @@ -376,6 +376,7 @@ mbp_open (int fd, dev_t file_devno) FILE *specfp = NULL; int32_t file_size = -1; int ret = -1; + char *logfile = NULL; glusterfs_handle_t handle = NULL; glusterfs_init_params_t ctx = { @@ -409,8 +410,13 @@ mbp_open (int fd, dev_t file_devno) goto out; fseek (specfp, 0L, SEEK_SET); - ctx.logfile = strdup (getenv (BOOSTER_LOG_ENV_VAR)); - if (!ctx.logfile) + logfile = getenv (BOOSTER_LOG_ENV_VAR); + if (logfile) { + if (strlen (logfile) > 0) + ctx.logfile = strdup (logfile); + else + ctx.logfile = strdup (BOOSTER_DEFAULT_LOG); + } else ctx.logfile = strdup (BOOSTER_DEFAULT_LOG); ctx.specfp = specfp; @@ -1178,10 +1184,13 @@ booster_init (void) * socket calls will fall-back to the real API. */ booster_conf_path = getenv (BOOSTER_CONF_ENV_VAR); - if (booster_conf_path == NULL) + if (booster_conf_path != NULL) { + if (strlen (booster_conf_path) > 0) + ret = booster_configure (booster_conf_path); + else + ret = booster_configure (DEFAULT_BOOSTER_CONF); + } else ret = booster_configure (DEFAULT_BOOSTER_CONF); - else - ret = booster_configure (booster_conf_path); if (ret == 0) gf_log ("booster", GF_LOG_DEBUG, "booster is inited"); -- cgit