Don't trust gmtime() to return usable structures for dates in the past.
authorFabian Keil <fk@fabiankeil.de>
Wed, 17 Jun 2009 18:23:06 +0000 (18:23 +0000)
committerFabian Keil <fk@fabiankeil.de>
Wed, 17 Jun 2009 18:23:06 +0000 (18:23 +0000)
Intended to fix the crashes anonymously reported in #2807350 and #2797798.

parsers.c

index 343d4a3..643c4f3 100644 (file)
--- 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.",