Skip to content
Snippets Groups Projects
Unverified Commit 97a1e53f authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #1892 from anastmag/work

Check localtime return value
parents 07917947 cc3afabc
No related branches found
No related tags found
No related merge requests found
......@@ -297,13 +297,13 @@ tsk_fs_meta_make_ls(const TSK_FS_META * a_fs_meta, char *a_buf,
char *
tsk_fs_time_to_str(time_t time, char buf[128])
{
struct tm *tmTime;
buf[0] = '\0';
if (time <= 0) {
if (time <= 0 || (tmTime = localtime(&time)) == NULL) {
strncpy(buf, "0000-00-00 00:00:00 (UTC)", 128);
}
else {
struct tm *tmTime = localtime(&time);
snprintf(buf, 128, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d (%s)",
(int) tmTime->tm_year + 1900,
(int) tmTime->tm_mon + 1, (int) tmTime->tm_mday,
......@@ -326,13 +326,13 @@ char *
tsk_fs_time_to_str_subsecs(time_t time, unsigned int subsecs,
char buf[128])
{
struct tm *tmTime;
buf[0] = '\0';
if (time <= 0) {
if (time <= 0 || (tmTime = localtime(&time)) == NULL) {
strncpy(buf, "0000-00-00 00:00:00 (UTC)", 32);
}
else {
struct tm *tmTime = localtime(&time);
snprintf(buf, 64, "%.4d-%.2d-%.2d %.2d:%.2d:%.2d.%.9d (%s)",
(int) tmTime->tm_year + 1900,
(int) tmTime->tm_mon + 1, (int) tmTime->tm_mday,
......@@ -368,12 +368,12 @@ tsk_fs_print_time(FILE * hFile, time_t time)
static void
tsk_fs_print_day(FILE * hFile, time_t time)
{
if (time <= 0) {
struct tm *tmTime;
if (time <= 0 || (tmTime = localtime(&time)) == NULL) {
tsk_fprintf(hFile, "0000-00-00 00:00:00 (UTC)");
}
else {
struct tm *tmTime = localtime(&time);
tsk_fprintf(hFile, "%.4d-%.2d-%.2d 00:00:00 (%s)",
(int) tmTime->tm_year + 1900,
(int) tmTime->tm_mon + 1, (int) tmTime->tm_mday,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment