Signed-off-by: Jakub Filak <[email protected]>
---
 src/gui-gtk/main.c |   24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/src/gui-gtk/main.c b/src/gui-gtk/main.c
index 12b14e9..1dab44b 100644
--- a/src/gui-gtk/main.c
+++ b/src/gui-gtk/main.c
@@ -180,18 +180,22 @@ static void add_directory_to_dirlist(const char 
*problem_dir_path, gpointer data
             return;
     }
 
-    char time_buf[sizeof("YYYY-MM-DD hh:mm:ss")];
-    time_buf[0] = '\0';
     const char *time_str = problem_data_get_content_or_NULL(pd, FILENAME_TIME);
-    time_t t = 0;
-    if (time_str && time_str[0])
+    char *endptr;
+    errno = 0;
+    time_t t = strtol(time_str, &endptr, 10);
+    if (errno != 0 || endptr == time_str || *endptr != '\0')
     {
-        t = strtol(time_str, NULL, 10); /* atoi won't work past 2038! */
-        struct tm *ptm = localtime(&t);
-        size_t time_len = strftime(time_buf, sizeof(time_buf)-1, "%Y-%m-%d 
%H:%M", ptm);
-        time_buf[time_len] = '\0';
+        /* we don't use error_msg() because we don't want to bother user */
+        log("'%s' is not valid problem because of invalid 'time' field 
('%s')", problem_dir_path, time_str);
+        goto finis_add_directory;
     }
 
+    struct tm *ptm = localtime(&t);
+    char time_buf[sizeof("YYYY-MM-DD hh:mm:ss")];
+    size_t time_len = strftime(time_buf, sizeof(time_buf)-1, "%Y-%m-%d %H:%M", 
ptm);
+    time_buf[time_len] = '\0';
+
     const char *not_reportable_reason = problem_data_get_content_or_NULL(pd, 
FILENAME_NOT_REPORTABLE);
     const char *reason = problem_data_get_content_or_NULL(pd, FILENAME_REASON);
 
@@ -225,9 +229,11 @@ static void add_directory_to_dirlist(const char 
*problem_dir_path, gpointer data
                           -1);
 
     free(subm_status);
-    problem_data_free(pd);
 
     VERB1 log("added: %s", problem_dir_path);
+
+finis_add_directory:
+    problem_data_free(pd);
 }
 
 static void query_dbus_and_add_to_dirlist(void)
-- 
1.7.10.4

Reply via email to