summaryrefslogtreecommitdiffstats
path: root/src/dir.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2014-01-25 13:34:21 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2014-01-25 13:34:21 +0100
commit6690fdd45ff41ae44e20ca72dfb2afab39010894 (patch)
tree09b030e2a7b2ae066af0e4c623491ad38624d4ec /src/dir.c
parent88d86389d5ba46bebb353e81f3ed617b9864b7c9 (diff)
Avoid additional NULL pointer derefence when localtime() failed
Diffstat (limited to 'src/dir.c')
-rw-r--r--src/dir.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/src/dir.c b/src/dir.c
index 7f3ba71..587ff52 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -162,20 +162,22 @@ 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(file_walker, file_info_t, list);
char datestr[80];
char str[11];
- if(current_file->td_mtime)
{
- const struct tm *tm_p = localtime(&current_file->td_mtime);
- 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)
+ const struct tm *tm_p;
+ if(current_file->td_mtime && (tm_p = localtime(&current_file->td_mtime))!=NULL)
{
- test_date=1;
+ 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));
}
- } else {
- strncpy(datestr, " ",sizeof(datestr));
}
mode_string(current_file->st_mode, str);
if((current_file->status&FILE_STATUS_DELETED)!=0)
@@ -219,21 +221,22 @@ int log_list_file(const disk_t *disk, const partition_t *partition, const dir_da
log_info("X");
else
log_info(" ");
- if(current_file->td_mtime)
{
- const struct tm *tm_p = localtime(&current_file->td_mtime);
-
- 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<=2012)
+ const struct tm *tm_p;
+ if(current_file->td_mtime && (tm_p = localtime(&current_file->td_mtime))!=NULL)
{
- test_date=1;
+ 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));
}
- } else {
- strncpy(datestr, " ",sizeof(datestr));
}
mode_string(current_file->st_mode, str);
log_info("%7lu ",(unsigned long int)current_file->st_ino);