diff --git a/darkhttpd.c b/darkhttpd.c index 350a56a..8a607ee 100644 --- a/darkhttpd.c +++ b/darkhttpd.c @@ -1301,8 +1301,9 @@ static void logencode(const char *src, char *dest) { static char *clf_date(char *dest, const time_t when) { time_t when_copy = when; if (strftime(dest, CLF_DATE_LEN, - "[%d/%b/%Y:%H:%M:%S %z]", localtime(&when_copy)) == 0) - errx(1, "strftime() failed [%s]", dest); + "[%d/%b/%Y:%H:%M:%S %z]", localtime(&when_copy)) == 0) { + dest[0] = 0; + } return dest; } @@ -1456,8 +1457,9 @@ static void poll_check_timeout(struct connection *conn) { static char *rfc1123_date(char *dest, const time_t when) { time_t when_copy = when; if (strftime(dest, DATE_LEN, - "%a, %d %b %Y %H:%M:%S GMT", gmtime(&when_copy)) == 0) - errx(1, "strftime() failed [%s]", dest); + "%a, %d %b %Y %H:%M:%S GMT", gmtime(&when_copy)) == 0) { + dest[0] = 0; + } return dest; } diff --git a/devel/test.py b/devel/test.py index 511d0af..a47bd4b 100755 --- a/devel/test.py +++ b/devel/test.py @@ -6,6 +6,7 @@ import signal import re import os import random +import time WWWROOT = "tmp.httpd.tests" @@ -470,6 +471,24 @@ class TestLargeFile2G(TestHelper): class TestLargeFile4G(TestLargeFile2G): BOUNDARY = 1<<32 +class TestLargeMtime(TestHelper): + def setUp(self): + self.url = '/large_mtime' + self.fn = WWWROOT + self.url + with open(self.fn, 'wb') as f: + f.write(b'x') + # A timestamp in the year 10,000 + t = int(time.mktime((10000,3,14,1,2,3,0,0,-1))) + os.utime(self.fn, (t, t)) + + def tearDown(self): + os.unlink(self.fn) + + def test_file_get(self): + resp = self.get(self.url) + status, hdrs, body = parse(resp) + self.assertContains(status, "200 OK") + if __name__ == '__main__': setUpModule() unittest.main()