From 9f8dc71d0e5b45cb3d8f6dd4664cd7f774a14373 Mon Sep 17 00:00:00 2001
From: Fabian Keil <fk@fabiankeil.de>
Date: Wed, 17 Jun 2009 18:23:06 +0000
Subject: [PATCH] Don't trust gmtime() to return usable structures for dates in
 the past.

Intended to fix the crashes anonymously reported in #2807350 and #2797798.
---
 parsers.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/parsers.c b/parsers.c
index 343d4a31..643c4f3a 100644
--- a/parsers.c
+++ b/parsers.c
@@ -1,4 +1,4 @@
-const char parsers_rcs[] = "$Id: parsers.c,v 1.181 2009/06/17 14:51:23 fabiankeil Exp $";
+const char parsers_rcs[] = "$Id: parsers.c,v 1.182 2009/06/17 14:51:51 fabiankeil Exp $";
 /*********************************************************************
  *
  * File        :  $Source: /cvsroot/ijbswa/current/parsers.c,v $
@@ -2334,8 +2334,8 @@ static jb_err server_last_modified(struct client_state *csp, char **header)
 #else
             timeptr = gmtime(&last_modified);
 #endif
-            if (!strftime(newheader, sizeof(newheader),
-                    "%a, %d %b %Y %H:%M:%S GMT", timeptr))
+            if ((NULL == timeptr) || !strftime(newheader,
+                  sizeof(newheader), "%a, %d %b %Y %H:%M:%S GMT", timeptr))
             {
                log_error(LOG_LEVEL_ERROR,
                   "Randomizing '%s' failed. Keeping the header unmodified.",
@@ -3061,8 +3061,8 @@ static jb_err client_if_modified_since(struct client_state *csp, char **header)
 #else
             timeptr = gmtime(&tm);
 #endif
-            if (!strftime(newheader, sizeof(newheader),
-                    "%a, %d %b %Y %H:%M:%S GMT", timeptr))
+            if ((NULL == timeptr) || !strftime(newheader,
+                  sizeof(newheader), "%a, %d %b %Y %H:%M:%S GMT", timeptr))
             {
                log_error(LOG_LEVEL_ERROR,
                   "Randomizing '%s' failed. Keeping the header unmodified.",
-- 
2.49.0