aboutsummaryrefslogtreecommitdiffstats
path: root/ringbuffer.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-04-17 22:54:04 -0700
committerGuy Harris <guy@alum.mit.edu>2017-04-18 05:54:34 +0000
commit6a049dd755a5c2c4c20669c8b4c9895d63ea2c15 (patch)
tree91ea958504d0c046d6178069f2a2daad65b2f83a /ringbuffer.c
parent720705091c0d3414ea9d291cf419e865b193672d (diff)
Check the result of localtime().
Unlikely to fail, but it squelches CID 1398219. Change-Id: Ibdabd2d71bdc2c09549f27f1ffe528005383ee3e Reviewed-on: https://code.wireshark.org/review/21178 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'ringbuffer.c')
-rw-r--r--ringbuffer.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/ringbuffer.c b/ringbuffer.c
index 099e8c4783..0ba365c25f 100644
--- a/ringbuffer.c
+++ b/ringbuffer.c
@@ -87,6 +87,7 @@ static int ringbuf_open_file(rb_file *rfile, int *err)
char filenum[5+1];
char timestr[14+1];
time_t current_time;
+ struct tm *tm;
if (rfile->name != NULL) {
if (rb_data.unlimited == FALSE) {
@@ -102,13 +103,11 @@ static int ringbuf_open_file(rb_file *rfile, int *err)
current_time = time(NULL);
g_snprintf(filenum, sizeof(filenum), "%05u", (rb_data.curr_file_num + 1) % RINGBUFFER_MAX_NUM_FILES);
- /*
- * XXX - We trust Windows not to return a time before the Epoch, so
- * localtime() doesn't return a null pointer. localtime() can probably
- * handle pre-Epoch times on most UN*X systems, and we trust them not
- * to return a time before the Epoch in any case.
- */
- strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", localtime(&current_time));
+ tm = localtime(&current_time);
+ if (tm != NULL)
+ strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", tm);
+ else
+ g_strlcpy(timestr, "196912312359", sizeof(timestr)); /* second before the Epoch */
rfile->name = g_strconcat(rb_data.fprefix, "_", filenum, "_", timestr,
rb_data.fsuffix, NULL);