Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion modules/dav/main/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ DAV_DECLARE(time_t) dav_get_timeout_string(request_rec *r,
sec = 0;
}

now = apr_time_sec(apr_time_now());
/* same clock as the expiry checks and the Timeout output */
now = time(NULL);

/* The RFC 4918 maximum of 2^32 - 1 does not necessarily
* fit a time_t on platforms where time_t is 32 bits.
Expand Down
46 changes: 43 additions & 3 deletions test/modules/dav/test_004_lock_timeout_overflow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import glob
import http.client
import os
import re
import time

import pytest

Expand Down Expand Up @@ -30,7 +32,7 @@ class TestLockTimeoutOverflow:
def _class_scope(cls, env):
dav_dir = os.path.join(env.gen_dir, 'dav-timeout-overflow')
os.makedirs(dav_dir, exist_ok=True)
for name in ('file1.txt', 'file2.txt', 'file3.txt'):
for name in ('file1.txt', 'file2.txt', 'file3.txt', 'file4.txt'):
with open(os.path.join(dav_dir, name), 'w') as fd:
fd.write('hello\n')

Expand Down Expand Up @@ -70,7 +72,8 @@ def test_dav_004_01(self, env):
assert r.response["status"] == 200, r.response
m = re.search(r'<D:timeout>([^<]*)</D:timeout>', r.stdout)
assert m, f"no <D:timeout> in response: {r.stdout}"
assert m.group(1) == "Second-4294967295", \
# a second may tick between the LOCK and its response
assert m.group(1) in ("Second-4294967295", "Second-4294967294"), \
f"timeout: {m.group(1)}"

# an ordinary, in-range timeout request is unaffected
Expand All @@ -79,7 +82,8 @@ def test_dav_004_02(self, env):
assert r.response["status"] == 200, r.response
m = re.search(r'<D:timeout>([^<]*)</D:timeout>', r.stdout)
assert m, f"no <D:timeout> in response: {r.stdout}"
assert m.group(1) == "Second-600", f"timeout: {m.group(1)}"
assert m.group(1) in ("Second-600", "Second-599"), \
f"timeout: {m.group(1)}"

# a Second- value with no digits at all parses the same way atol()
# already did (0, not an error), same as before this fix: an
Expand All @@ -91,3 +95,39 @@ def test_dav_004_03(self, env):
m = re.search(r'<D:timeout>([^<]*)</D:timeout>', r.stdout)
assert m, f"no <D:timeout> in response: {r.stdout}"
assert m.group(1) == "Second-0", f"timeout: {m.group(1)}"

# the expiry, the expiry check and the reported remaining time
# come from the same clock: a lock expiring "now" is never still
# held and never reports a second left, even when the LOCK lands
# right after a second boundary
def test_dav_004_04(self, env):
conn = http.client.HTTPConnection(env.http_addr, env.http_port,
timeout=10)
headers = {
'Host': f"test1.{env.http_tld}",
'Timeout': 'Second-0',
'Content-Type': 'text/xml',
}
bad = []
count = 0
# span several second boundaries
end = time.time() + 3.5
try:
while time.time() < end:
conn.request('LOCK', '/dav-timeout-overflow/file4.txt',
body=LOCK_BODY, headers=headers)
resp = conn.getresponse()
body = resp.read().decode()
count += 1
if resp.status != 200:
# a lock expiring "now" is still held: 423
bad.append(resp.status)
continue
m = re.search(r'<D:timeout>([^<]*)</D:timeout>', body)
assert m, f"no <D:timeout> in response: {body}"
if m.group(1) != "Second-0":
bad.append(m.group(1))
finally:
conn.close()
assert not bad, \
f"{len(bad)} of {count} locks: {sorted(set(map(str, bad)))}"
Loading