summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2017-04-15 12:00:24 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2017-04-15 12:00:24 +0200
commita1419a0806b4270bfad92ea496624b2edee5062c (patch)
treed08d076cd116f0a05092d49ddac393bfc82ab3b9
parent1cba494e472d280483cc3bf05940efd061846a9e (diff)
Use localtime_t() instead of localtime()
-rw-r--r--configure.ac4
-rw-r--r--src/askloc.c14
-rw-r--r--src/common.c11
-rw-r--r--src/common.h3
-rw-r--r--src/dfxml.c3
-rw-r--r--src/dir.c57
-rw-r--r--src/dir.h1
-rw-r--r--src/dirn.c16
-rw-r--r--src/fat_adv.c14
-rw-r--r--src/ntfs_udl.c16
10 files changed, 45 insertions, 94 deletions
diff --git a/configure.ac b/configure.ac
index fe000e2..58369d2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -6,7 +6,7 @@ AC_INIT([testdisk],[7.1-WIP],[grenier@cgsecurity.org])
AC_LANG(C)
sinclude(acx_pthread.m4)
sinclude(mkdir.m4)
-TESTDISKDATE="August 2016"
+TESTDISKDATE="April 2017"
AC_SUBST(TESTDISKDATE)
AC_DEFINE_UNQUOTED([TESTDISKDATE],"$TESTDISKDATE",[Date of release])
AC_CONFIG_AUX_DIR(config)
@@ -872,7 +872,7 @@ case "$target" in
;;
esac
-AC_CHECK_FUNCS([ atexit atoll chdir chmod delscreen dirname dup2 execv fdatasync fseeko fsync ftello ftruncate getcwd geteuid getpwuid libewf_handle_read_buffer_at_offset libewf_handle_write_buffer_at_offset lstat memalign memchr memset mkdir posix_fadvise posix_memalign pwrite readlink setenv setlocale sigaction signal sleep snprintf strcasecmp strcasestr strchr strdup strerror strncasecmp strptime strrchr strstr strtol strtoul strtoull touchwin uname utime vsnprintf wctomb ])
+AC_CHECK_FUNCS([ atexit atoll chdir chmod delscreen dirname dup2 execv fdatasync fseeko fsync ftello ftruncate getcwd geteuid getpwuid libewf_handle_read_buffer_at_offset libewf_handle_write_buffer_at_offset localtime_r lstat memalign memchr memset mkdir posix_fadvise posix_memalign pwrite readlink setenv setlocale sigaction signal sleep snprintf strcasecmp strcasestr strchr strdup strerror strncasecmp strptime strrchr strstr strtol strtoul strtoull touchwin uname utime vsnprintf wctomb ])
if test "$ac_cv_func_mkdir" = "no"; then
AC_MSG_ERROR(No mkdir function detected)
fi
diff --git a/src/askloc.c b/src/askloc.c
index 3fe8480..792ed2b 100644
--- a/src/askloc.c
+++ b/src/askloc.c
@@ -79,7 +79,6 @@ char *get_default_location(void)
}
#ifdef HAVE_NCURSES
-extern const char *monstr[];
#ifdef __MINGW32__
#define SPATH_SEP "\\"
@@ -575,18 +574,7 @@ static void dir_aff_entry(WINDOW *window, file_info_t *file_info)
{
char str[11];
char datestr[80];
- {
- const struct tm *tm_p;
- if(file_info->td_mtime!=0 && (tm_p= localtime(&file_info->td_mtime))!=NULL)
- {
- snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
- tm_p->tm_mday, monstr[tm_p->tm_mon],
- 1900 + tm_p->tm_year, tm_p->tm_hour,
- tm_p->tm_min);
- } else {
- strncpy(datestr, " ",sizeof(datestr));
- }
- }
+ set_datestr((char *)&datestr, sizeof(datestr), file_info->td_mtime);
mode_string(file_info->st_mode, str);
wprintw(window, "%s %5u %5u ",
str, (unsigned int)file_info->st_uid, (unsigned int)file_info->st_gid);
diff --git a/src/common.c b/src/common.c
index 2a14ccf..a4458b3 100644
--- a/src/common.c
+++ b/src/common.c
@@ -166,6 +166,14 @@ char * strcasestr (const char *haystack, const char *needle)
return NULL;
}
#endif
+
+#ifndef HAVE_LOCALTIME_R
+struct tm *localtime_r(const time_t *timep, struct tm *result)
+{
+ return localtime(timep);
+}
+#endif
+
unsigned int up2power(const unsigned int number)
{
/* log_trace("up2power(%u)=>%u\n",number, (1<<up2power_aux(number-1))); */
@@ -239,7 +247,8 @@ int date_dos2unix(const unsigned short f_time, const unsigned short f_date)
void set_secwest(void)
{
const time_t t = time(NULL);
- const struct tm *tmptr = localtime(&t);
+ struct tm tmp;
+ const struct tm *tmptr = localtime_r(&t,&tmp);
#ifdef HAVE_STRUCT_TM_TM_GMTOFF
if(tmptr)
secwest = -1 * tmptr->tm_gmtoff;
diff --git a/src/common.h b/src/common.h
index 3154047..28bad5d 100644
--- a/src/common.h
+++ b/src/common.h
@@ -496,6 +496,9 @@ int strncasecmp(const char * s1, const char * s2, size_t len);
#ifndef HAVE_STRCASESTR
char * strcasestr (const char *haystack, const char *needle);
#endif
+#ifndef HAVE_LOCALTIME_R
+struct tm *localtime_r(const time_t *timep, struct tm *result);
+#endif
/*
* td_min()/td_max() macros that also do
* strict type-checking.. See the
diff --git a/src/dfxml.c b/src/dfxml.c
index 1a99f04..c9da693 100644
--- a/src/dfxml.c
+++ b/src/dfxml.c
@@ -253,7 +253,8 @@ void xml_add_DFXML_creator(const char *package, const char *version)
{
char outstr[200];
const time_t t = time(NULL);
- const struct tm *tmp = localtime(&t);
+ struct tm tm_tmp;
+ const struct tm *tmp = localtime_r(&t,&tm_tmp);
if (tmp != NULL &&
strftime(outstr, sizeof(outstr), "%Y-%m-%dT%H:%M:%S%z", tmp) != 0)
{
diff --git a/src/dir.c b/src/dir.c
index ee9c16d..85b7689 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -153,6 +153,27 @@ void mode_string (const unsigned int mode, char *str)
#endif
}
+int set_datestr(char *datestr, size_t n, const time_t timev)
+{
+ int test_date=0;
+ struct tm tmp;
+ const struct tm *tm_p;
+ if(timev!=0 && (tm_p= localtime_r(&timev, &tmp))!=NULL)
+ {
+ snprintf(datestr, n,"%2d-%s-%4d %02d:%02d",
+ tm_p->tm_mday, monstr[tm_p->tm_mon],
+ 1900 + tm_p->tm_year, tm_p->tm_hour,
+ tm_p->tm_min);
+ if(1900+tm_p->tm_year>=2000 && 1900+tm_p->tm_year<=2014)
+ {
+ test_date=1;
+ }
+ } else {
+ strncpy(datestr, " ", n);
+ }
+ return test_date;
+}
+
int dir_aff_log(const dir_data_t *dir_data, const file_info_t *dir_list)
{
int test_date=0;
@@ -166,23 +187,7 @@ int dir_aff_log(const dir_data_t *dir_data, const file_info_t *dir_list)
const file_info_t *current_file=td_list_entry_const(file_walker, const file_info_t, list);
char datestr[80];
char str[11];
- {
- const struct tm *tm_p;
- if(current_file->td_mtime && (tm_p = localtime(&current_file->td_mtime))!=NULL)
- {
- snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
- tm_p->tm_mday, monstr[tm_p->tm_mon],
- 1900 + tm_p->tm_year, tm_p->tm_hour,
- tm_p->tm_min);
- /* FIXME: a check using current_file->name will be better */
- if(1900+tm_p->tm_year>=2000 && 1900+tm_p->tm_year<=2014)
- {
- test_date=1;
- }
- } else {
- strncpy(datestr, " ",sizeof(datestr));
- }
- }
+ test_date=set_datestr((char *)&datestr, sizeof(datestr), current_file->td_mtime);
mode_string(current_file->st_mode, str);
if((current_file->status&FILE_STATUS_DELETED)!=0)
log_info("X");
@@ -225,23 +230,7 @@ int log_list_file(const disk_t *disk, const partition_t *partition, const dir_da
log_info("X");
else
log_info(" ");
- {
- const struct tm *tm_p;
- if(current_file->td_mtime && (tm_p = localtime(&current_file->td_mtime))!=NULL)
- {
- snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
- tm_p->tm_mday, monstr[tm_p->tm_mon],
- 1900 + tm_p->tm_year, tm_p->tm_hour,
- tm_p->tm_min);
- /* FIXME: a check using current_file->name will be better */
- if(1900+tm_p->tm_year>=2000 && 1900+tm_p->tm_year<=2014)
- {
- test_date=1;
- }
- } else {
- strncpy(datestr, " ",sizeof(datestr));
- }
- }
+ test_date=set_datestr((char *)&datestr, sizeof(datestr), current_file->td_mtime);
mode_string(current_file->st_mode, str);
log_info("%7lu ",(unsigned long int)current_file->st_ino);
log_info("%s %5u %5u ",
diff --git a/src/dir.h b/src/dir.h
index 3f85719..33be561 100644
--- a/src/dir.h
+++ b/src/dir.h
@@ -74,6 +74,7 @@ struct dir_data
#define FILE_STATUS_MARKED 2
#define FILE_STATUS_ADS 4
+int set_datestr(char *datestr, size_t n, const time_t timev);
int dir_aff_log(const dir_data_t *dir_data, const file_info_t*dir_list);
int log_list_file(const disk_t *disk_car, const partition_t *partition, const dir_data_t *dir_data, const file_info_t*list);
unsigned int delete_list_file(file_info_t *list);
diff --git a/src/dirn.c b/src/dirn.c
index 07f8ac2..588b65e 100644
--- a/src/dirn.c
+++ b/src/dirn.c
@@ -45,8 +45,6 @@
#include "askloc.h"
#include "setdate.h"
-extern const char *monstr[];
-
static int copy_dir(WINDOW *window, disk_t *disk, const partition_t *partition, dir_data_t *dir_data, const file_info_t *dir, unsigned int *copy_ok, unsigned int *copy_bad);
static int copy_selection(file_info_t*dir_list, WINDOW *window, disk_t *disk, const partition_t *partition, dir_data_t *dir_data, unsigned int *copy_ok, unsigned int *copy_bad);
@@ -152,19 +150,7 @@ static long int dir_aff_ncurses(disk_t *disk, const partition_t *partition, dir_
else if((current_file->status&FILE_STATUS_DELETED)!=0)
wbkgdset(window,' ' | COLOR_PAIR(1));
}
- {
- const struct tm *tm_p;
- if(current_file->td_mtime!=0 && (tm_p = localtime(&current_file->td_mtime))!=NULL)
- {
- snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
- tm_p->tm_mday, monstr[tm_p->tm_mon],
- 1900 + tm_p->tm_year, tm_p->tm_hour,
- tm_p->tm_min);
- /* May have to use %d instead of %e */
- } else {
- strncpy(datestr, " ",sizeof(datestr));
- }
- }
+ set_datestr((char *)&datestr, sizeof(datestr), current_file->td_mtime);
mode_string(current_file->st_mode, str);
wprintw(window, "%s %5u %5u ",
str, (unsigned int)current_file->st_uid, (unsigned int)current_file->st_gid);
diff --git a/src/fat_adv.c b/src/fat_adv.c
index aef17ec..8444263 100644
--- a/src/fat_adv.c
+++ b/src/fat_adv.c
@@ -62,7 +62,6 @@
#define INTER_FAT_ASK_Y 23
#define INTER_FATBS_X 0
#define INTER_FATBS_Y 22
-extern const char *monstr[];
typedef struct info_offset_struct info_offset_t;
@@ -217,18 +216,7 @@ static int ask_root_directory(disk_t *disk_car, const partition_t *partition, co
}
else
waddstr(window, " ");
- {
- const struct tm *tm_p;
- if(current_file->td_mtime!=0 && (tm_p=localtime(&current_file->td_mtime))!=NULL)
- {
- snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
- tm_p->tm_mday, monstr[tm_p->tm_mon],
- 1900 + tm_p->tm_year, tm_p->tm_hour,
- tm_p->tm_min);
- } else {
- strncpy(datestr, " ",sizeof(datestr));
- }
- }
+ set_datestr((char *)&datestr, sizeof(datestr), current_file->td_mtime);
mode_string(current_file->st_mode, str);
wprintw(window, "%s %3u %3u ",
str, (unsigned int)current_file->st_uid, (unsigned int)current_file->st_gid);
diff --git a/src/ntfs_udl.c b/src/ntfs_udl.c
index 3827841..d16fa94 100644
--- a/src/ntfs_udl.c
+++ b/src/ntfs_udl.c
@@ -110,8 +110,6 @@
#include "askloc.h"
#include "setdate.h"
-extern const char *monstr[];
-
struct options {
char *dest; /* Save file to this directory */
};
@@ -1265,19 +1263,7 @@ static void ntfs_undelete_menu_ncurses(disk_t *disk_car, const partition_t *part
waddstr(window, " ");
if((file_info->status&FILE_STATUS_MARKED)!=0 && has_colors())
wbkgdset(window,' ' | COLOR_PAIR(2));
- {
- const struct tm *tm_p;
- if(file_info->td_mtime!=0 && (tm_p=localtime(&file_info->td_mtime))!=NULL)
- {
- snprintf(datestr, sizeof(datestr),"%2d-%s-%4d %02d:%02d",
- tm_p->tm_mday, monstr[tm_p->tm_mon],
- 1900 + tm_p->tm_year, tm_p->tm_hour,
- tm_p->tm_min);
- /* May have to use %d instead of %e */
- } else {
- strncpy(datestr, " ",sizeof(datestr));
- }
- }
+ set_date((char *)&datestr, sizeof(datestr), file_info->td_mtime);
if(COLS <= 1+17+1+9+1)
wprintw(window, "%s", file_info->name);
else