diff options
author | Amar Tumballi <amarts@redhat.com> | 2018-07-13 14:45:31 +0530 |
---|---|---|
committer | Shyamsundar Ranganathan <srangana@redhat.com> | 2018-11-12 15:41:19 +0000 |
commit | c20122d6e9ad949a803d6ed78e120f9f7242e26d (patch) | |
tree | 0323b8d50ef1cc1ee5c6a19e202c795fcf987c07 | |
parent | e65f1ad03536a2de811d5092b665905af59934fb (diff) | |
download | glusterfs-c20122d6e9ad949a803d6ed78e120f9f7242e26d.tar.gz glusterfs-c20122d6e9ad949a803d6ed78e120f9f7242e26d.tar.xz glusterfs-c20122d6e9ad949a803d6ed78e120f9f7242e26d.zip |
logging: check for fmts not being NULL
this fix is just a review of possible SIGSEGV issues in line 714
as per crash report at the bug:
```
08:35:25 Program terminated with signal 11, Segmentation fault.
08:35:25 #0 0x00007f4ebb491c5c in gf_time_fmt (dst=0x7f4eb1ff9a90 "", sz_dst=256, utime=1531470915, fmt=0)
at /home/jenkins/root/workspace/centos7-regression/libglusterfs/src/common-utils.h:714
```
fixes: bz#1648367
Change-Id: I160c391f8ac1a3456e59103d293b24e0e3fae718
Signed-off-by: Amar Tumballi <amarts@redhat.com>
(cherry picked from commit 6c2deb080aa2df73d3cb2a5f330208d30e9c6759)
-rw-r--r-- | libglusterfs/src/common-utils.c | 3 | ||||
-rw-r--r-- | libglusterfs/src/common-utils.h | 14 |
2 files changed, 10 insertions, 7 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 6c28690c8f..e2874602a8 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -3096,9 +3096,8 @@ static const char *__gf_zerotimes[] = { }; void -_gf_timestuff (gf_timefmts *fmt, const char ***fmts, const char ***zeros) +_gf_timestuff (const char ***fmts, const char ***zeros) { - *fmt = gf_timefmt_last; *fmts = __gf_timefmts; *zeros = __gf_zerotimes; } diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h index 2bad5b4736..8b6f0f1ea7 100644 --- a/libglusterfs/src/common-utils.h +++ b/libglusterfs/src/common-utils.h @@ -695,19 +695,23 @@ typedef enum { static inline char * gf_time_fmt (char *dst, size_t sz_dst, time_t utime, unsigned int fmt) { - extern void _gf_timestuff (gf_timefmts *, const char ***, const char ***); + extern void _gf_timestuff (const char ***, const char ***); static gf_timefmts timefmt_last = (gf_timefmts) - 1; static const char **fmts; static const char **zeros; struct tm tm, *res; int localtime = 0; - if (timefmt_last == (gf_timefmts) - 1) - _gf_timestuff (&timefmt_last, &fmts, &zeros); - if (timefmt_last < fmt) fmt = gf_timefmt_default; + if (timefmt_last == ((gf_timefmts)-1)) { + _gf_timestuff (&fmts, &zeros); + timefmt_last = gf_timefmt_last; + } + if (timefmt_last <= fmt) { + fmt = gf_timefmt_default; + } localtime = gf_log_get_localtime (); res = localtime ? localtime_r (&utime, &tm) : gmtime_r (&utime, &tm); - if (utime && res != NULL) { + if (utime && (res != NULL)) { strftime (dst, sz_dst, fmts[fmt], &tm); } else { strncpy (dst, "N/A", sz_dst); |