mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
Fix crash when a file has a large (year 10,000+) mtime.
https://bugzilla.redhat.com/show_bug.cgi?id=1893725 https://github.com/emikulic/darkhttpd/issues/21
This commit is contained in:
parent
1f166293b7
commit
1eb6daa357
10
darkhttpd.c
10
darkhttpd.c
@ -1301,8 +1301,9 @@ static void logencode(const char *src, char *dest) {
|
|||||||
static char *clf_date(char *dest, const time_t when) {
|
static char *clf_date(char *dest, const time_t when) {
|
||||||
time_t when_copy = when;
|
time_t when_copy = when;
|
||||||
if (strftime(dest, CLF_DATE_LEN,
|
if (strftime(dest, CLF_DATE_LEN,
|
||||||
"[%d/%b/%Y:%H:%M:%S %z]", localtime(&when_copy)) == 0)
|
"[%d/%b/%Y:%H:%M:%S %z]", localtime(&when_copy)) == 0) {
|
||||||
errx(1, "strftime() failed [%s]", dest);
|
dest[0] = 0;
|
||||||
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1456,8 +1457,9 @@ static void poll_check_timeout(struct connection *conn) {
|
|||||||
static char *rfc1123_date(char *dest, const time_t when) {
|
static char *rfc1123_date(char *dest, const time_t when) {
|
||||||
time_t when_copy = when;
|
time_t when_copy = when;
|
||||||
if (strftime(dest, DATE_LEN,
|
if (strftime(dest, DATE_LEN,
|
||||||
"%a, %d %b %Y %H:%M:%S GMT", gmtime(&when_copy)) == 0)
|
"%a, %d %b %Y %H:%M:%S GMT", gmtime(&when_copy)) == 0) {
|
||||||
errx(1, "strftime() failed [%s]", dest);
|
dest[0] = 0;
|
||||||
|
}
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@ import signal
|
|||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
WWWROOT = "tmp.httpd.tests"
|
WWWROOT = "tmp.httpd.tests"
|
||||||
|
|
||||||
@ -470,6 +471,24 @@ class TestLargeFile2G(TestHelper):
|
|||||||
class TestLargeFile4G(TestLargeFile2G):
|
class TestLargeFile4G(TestLargeFile2G):
|
||||||
BOUNDARY = 1<<32
|
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__':
|
if __name__ == '__main__':
|
||||||
setUpModule()
|
setUpModule()
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
Loading…
Reference in New Issue
Block a user