aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--libsylph/procheader.c11
-rw-r--r--libsylph/utils.c14
3 files changed, 27 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index f75bf665..29b6dce1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-10-10
+
+ * libsylph/utils.c
+ libsylph/procheader.c: fixed a bug that caused crashes on receive
+ if Date: header has abnormal time.
+
2005-10-07
* libsylph/recv.[ch]
diff --git a/libsylph/procheader.c b/libsylph/procheader.c
index 9267ead1..82a1d615 100644
--- a/libsylph/procheader.c
+++ b/libsylph/procheader.c
@@ -768,6 +768,12 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
t.tm_isdst = -1;
timer = mktime(&t);
+ if (timer == -1) {
+ if (dest)
+ dest[0] = '\0';
+ return 0;
+ }
+
tz_offset = remote_tzoffset_sec(zone);
if (tz_offset != -1)
timer += tzoffset_sec(&timer) - tz_offset;
@@ -787,6 +793,11 @@ void procheader_date_get_localtime(gchar *dest, gint len, const time_t timer)
Xalloca(tmp, len + 1, dest[0] = '\0'; return;);
lt = localtime(&timer);
+ if (!lt) {
+ g_warning("can't get localtime of %d\n", timer);
+ dest[0] = '\0';
+ return;
+ }
if (prefs_common.date_format)
strftime(tmp, len, prefs_common.date_format, lt);
diff --git a/libsylph/utils.c b/libsylph/utils.c
index f9ebba5a..0ddae386 100644
--- a/libsylph/utils.c
+++ b/libsylph/utils.c
@@ -3175,11 +3175,14 @@ time_t remote_tzoffset_sec(const gchar *zone)
time_t tzoffset_sec(time_t *now)
{
- struct tm gmt, *lt;
+ struct tm gmt, *tmp, *lt;
gint off;
- gmt = *gmtime(now);
+ tmp = gmtime(now);
+ g_return_val_if_fail(tmp != NULL, -1);
+ gmt = *tmp;
lt = localtime(now);
+ g_return_val_if_fail(lt != NULL, -1);
off = (lt->tm_hour - gmt.tm_hour) * 60 + lt->tm_min - gmt.tm_min;
@@ -3204,12 +3207,15 @@ time_t tzoffset_sec(time_t *now)
gchar *tzoffset(time_t *now)
{
static gchar offset_string[6];
- struct tm gmt, *lt;
+ struct tm gmt, *tmp, *lt;
gint off;
gchar sign = '+';
- gmt = *gmtime(now);
+ tmp = gmtime(now);
+ g_return_val_if_fail(tmp != NULL, NULL);
+ gmt = *tmp;
lt = localtime(now);
+ g_return_val_if_fail(lt != NULL, NULL);
off = (lt->tm_hour - gmt.tm_hour) * 60 + lt->tm_min - gmt.tm_min;