diff options
author | Humble Devassy Chirammal <hchiramm@redhat.com> | 2015-04-07 18:43:30 +0530 |
---|---|---|
committer | Vijay Bellur <vbellur@redhat.com> | 2015-04-25 07:27:54 -0700 |
commit | b855aa062927ea4845f56d2d1a1a2a8af3dc4192 (patch) | |
tree | 11459fb85dd49d35b44e25758992fdf9a04c7ca8 /libglusterfs | |
parent | f6e24fc54453669f3943e50f44cce9bb6070a71a (diff) |
libglusterfs: avoid crash due to ctx being NULL
Change-Id: Ib667ed42f0b598baddb829b448d6efc3d8e044f1
Signed-off-by: Humble Devassy Chirammal <hchiramm@redhat.com>
Reviewed-on: http://review.gluster.org/10155
Tested-by: Gluster Build System <jenkins@build.gluster.com>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
Reviewed-by: Vijay Bellur <vbellur@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r-- | libglusterfs/src/logging.c | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/libglusterfs/src/logging.c b/libglusterfs/src/logging.c index 774dd092660..e8fca2db916 100644 --- a/libglusterfs/src/logging.c +++ b/libglusterfs/src/logging.c @@ -125,7 +125,7 @@ gf_log_get_loglevel (void) if (ctx) return ctx->log.loglevel; else - /* return global defaluts (see gf_log_globals_init) */ + /* return global defaults (see gf_log_globals_init) */ return GF_LOG_INFO; } @@ -689,6 +689,10 @@ gf_log_init (void *data, const char *file, const char *ident) ctx = data; + if (ctx == NULL) { + fprintf (stderr, "ERROR: ctx is NULL\n"); + return -1; + } if (ident) { ctx->log.ident = gf_strdup (ident); } @@ -798,6 +802,9 @@ _gf_log_callingfn (const char *domain, const char *file, const char *function, this = THIS; ctx = this->ctx; + if (!ctx) + goto out; + if (ctx->log.gf_log_xl_log_set) { if (this->loglevel && (level > this->loglevel)) goto out; @@ -1517,6 +1524,9 @@ gf_glusterlog_log_repetitions (glusterfs_ctx_t *ctx, const char *domain, char *footer = NULL; char *msg = NULL; + if (!ctx) + goto err; + gf_log_rotate (ctx); gf_time_fmt (timestr_latest, sizeof timestr_latest, latest.tv_sec, @@ -1776,6 +1786,9 @@ __gf_log_inject_timer_event (glusterfs_ctx_t *ctx) int ret = -1; struct timespec timeout = {0,}; + if (!ctx) + goto out; + if (ctx->log.log_flush_timer) { gf_timer_call_cancel (ctx, ctx->log.log_flush_timer); ctx->log.log_flush_timer = NULL; @@ -1853,6 +1866,9 @@ _gf_msg_internal (const char *domain, const char *file, const char *function, this = THIS; ctx = this->ctx; + if (!ctx) + goto out; + GET_FILE_NAME_TO_LOG (file, basename); ret = gettimeofday (&tv, NULL); @@ -2112,6 +2128,9 @@ _gf_log (const char *domain, const char *file, const char *function, int line, this = THIS; ctx = this->ctx; + if (!ctx) + goto out; + if (ctx->log.gf_log_xl_log_set) { if (this->loglevel && (level > this->loglevel)) goto out; @@ -2322,6 +2341,9 @@ gf_cmd_log_init (const char *filename) this = THIS; ctx = this->ctx; + if (!ctx) + return -1; + if (!filename){ gf_log (this->name, GF_LOG_CRITICAL, "gf_cmd_log_init: no " "filename specified\n"); @@ -2373,6 +2395,10 @@ gf_cmd_log (const char *domain, const char *fmt, ...) glusterfs_ctx_t *ctx = NULL; ctx = THIS->ctx; + + if (!ctx) + return -1; + if (!ctx->log.cmdlogfile) return -1; |