summaryrefslogtreecommitdiff
path: root/wsutil
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-04-17 22:43:22 -0700
committerGuy Harris <guy@alum.mit.edu>2017-04-18 05:43:54 +0000
commit720705091c0d3414ea9d291cf419e865b193672d (patch)
treee3be9908d3cb14b2b84b019021e01fea6df490be /wsutil
parent613476fbaf26bdcc427e661b4144f226b3319abd (diff)
downloadwireshark-720705091c0d3414ea9d291cf419e865b193672d.tar.gz
Check the result of localtime().
Unlikely to fail, but it squelches CID 1398220. Change-Id: I0e40146f0a32c1082e84052c6b3e382fe6a15ae7 Reviewed-on: https://code.wireshark.org/review/21177 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/tempfile.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/wsutil/tempfile.c b/wsutil/tempfile.c
index 5900b2bb8a..8e1f8dc588 100644
--- a/wsutil/tempfile.c
+++ b/wsutil/tempfile.c
@@ -170,6 +170,7 @@ create_tempfile(char **namebuf, const char *pfx, const char *sfx)
int old_umask;
int fd;
time_t current_time;
+ struct tm *tm;
char timestr[14 + 1];
gchar *tmp_file;
gchar *safe_pfx;
@@ -204,8 +205,11 @@ create_tempfile(char **namebuf, const char *pfx, const char *sfx)
_tzset();
#endif
current_time = time(NULL);
- /* We trust the OS not to return a time before the Epoch. */
- 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 */
sep[0] = G_DIR_SEPARATOR;
tmp_file = g_strconcat(tmp_dir, sep, safe_pfx, "_", timestr, "_", TMP_FILE_SUFFIX, sfx, NULL);
g_free(safe_pfx);