[LIBREPORT PATCH] Fix problem_item_format() to work properly after 2038 on x32. #691

Denys Vlasenko dvlasenk at redhat.com
Tue Sep 3 14:29:32 UTC 2013


Signed-off-by: Denys Vlasenko <dvlasenk at redhat.com>
---
 src/lib/problem_data.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/lib/problem_data.c b/src/lib/problem_data.c
index c3da1e7..ea2c94e 100644
--- a/src/lib/problem_data.c
+++ b/src/lib/problem_data.c
@@ -37,9 +37,12 @@ char *problem_item_format(struct problem_item *item)
     {
         errno = 0;
         char *end;
-        time_t time = strtol(item->content, &end, 10);
-        if (!errno && !*end && end != item->content)
-        {
+        /* On x32 arch, time_t is wider than long. Must use strtoll */
+        long long ll = strtoll(item->content, &end, 10);
+        time_t time = ll;
+        if (!errno && *end == '\0' && end != item->content
+         && ll == time /* there was no truncation in long long -> time_t conv */
+        ) {
             char timeloc[256];
             int success = strftime(timeloc, sizeof(timeloc), "%c", localtime(&time));
             if (success)
-- 
1.8.1.4



More information about the Crash-catcher mailing list