Skip to content
Closed
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: 3 additions & 0 deletions changes-entries/autoindex-terminate-description-bounds.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*) mod_autoindex: Stop reading (and writing) one byte past the end of a
file description when it ends inside an unterminated "&" entity or "<"
tag, as a ScanHTMLTitles title can. [arshiya tabasum]
19 changes: 9 additions & 10 deletions modules/generators/mod_autoindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -1452,22 +1452,21 @@ static char *terminate_description(autoindex_config_rec *d, char *desc,
}
for (x = 0; desc[x] && ((maxsize > 0) || (desc[x] == '<')); x++) {
if (desc[x] == '<') {
while (desc[x] != '>') {
if (!desc[x]) {
maxsize = 0;
break;
}
while (desc[x] && desc[x] != '>') {
++x;
}
if (!desc[x]) {
break;
}
}
else if (desc[x] == '&') {
/* entities like &auml; count as one character */
--maxsize;
for ( ; desc[x] != ';'; ++x) {
if (desc[x] == '\0') {
maxsize = 0;
break;
}
for ( ; desc[x] && desc[x] != ';'; ++x) {
;
}
if (!desc[x]) {
break;
}
}
else {
Expand Down
2 changes: 1 addition & 1 deletion test/modules/generators/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GeneratorsTestSetup(HttpdTestSetup):
def __init__(self, env: 'HttpdTestEnv'):
super().__init__(env=env)
self.add_source_dir(os.path.dirname(inspect.getfile(GeneratorsTestSetup)))
self.add_modules(["cgid", "include", "headers"])
self.add_modules(["cgid", "include", "headers", "autoindex"])


class GeneratorsTestEnv(HttpdTestEnv):
Expand Down
1 change: 1 addition & 0 deletions test/modules/generators/htdocs/autoindex/listing/att.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<html><head><title>AT&T</title></head><body>page</body></html>
34 changes: 34 additions & 0 deletions test/modules/generators/test_002_autoindex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import textwrap

import pytest

from pyhttpd.conf import HttpdConf


class TestAutoindex:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
domain = f"autoindex.{env.http_tld}"
conf = HttpdConf(env, extras={
'base': textwrap.dedent(f"""
LogLevel autoindex:trace1
<Directory "{env.server_docs_dir}/autoindex/listing">
Options +Indexes
IndexOptions FancyIndexing ScanHTMLTitles
</Directory>
"""),
})
conf.add_vhost(domains=[domain], port=env.http_port,
doc_root="htdocs/autoindex")
conf.install()
assert env.apache_restart() == 0

def test_generators_002_01_scan_title_bare_amp(self, env):
"""A ScanHTMLTitles description ending in a bare '&' (no ';'), as in
an "AT&T" <title>, must be rendered without reading past the end of
the description. Before the fix this walked one byte past the
terminating NUL, which ASAN flags as a heap over-read."""
r = env.curl_get(env.mkurl("http", "autoindex", "/listing/"))
assert r.response["status"] == 200
assert "AT&T" in r.response["body"].decode()