Skip to content
Open
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-charset-meta.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*) mod_autoindex: Emit the charset given by "IndexOptions Charset=" in a
<meta> tag of the generated page for HTML 4.01 as well as XHTML, ahead
of the page title. PR 69930.
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]
47 changes: 27 additions & 20 deletions modules/generators/mod_autoindex.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,17 @@ static void emit_preamble(request_rec *r, int xhtml, const char *title)
if (xhtml) {
ap_rvputs(r, DOCTYPE_XHTML_1_0T,
"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
" <head>\n <title>Index of ", title,
"</title>\n", NULL);
} else {
ap_rvputs(r, DOCTYPE_HTML_4_01,
"<html>\n <head>\n"
" <title>Index of ", title,
"</title>\n", NULL);
" <head>\n", NULL);
}
else {
ap_rvputs(r, DOCTYPE_HTML_4_01, "<html>\n <head>\n", NULL);
}

if (d->charset != NULL && *d->charset) {
ap_rvputs(r, " <meta http-equiv=\"Content-Type\" content=\"text/html; "
"charset=", d->charset, xhtml ? "\" />\n" : "\">\n", NULL);
}
ap_rvputs(r, " <title>Index of ", title, "</title>\n", NULL);

if (d->style_sheet != NULL) {
ap_rvputs(r, " <link rel=\"stylesheet\" href=\"", d->style_sheet,
Expand Down Expand Up @@ -457,8 +460,8 @@ static const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[
else {
int width = atoi(&w[10]);

if (width && (width < 5)) {
return "NameWidth value must be greater than 5";
if (width < 5) {
return "NameWidth value must be at least 5";
}
d_cfg->name_width = width;
d_cfg->name_adjust = K_NOADJUST;
Expand Down Expand Up @@ -1440,22 +1443,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 Expand Up @@ -1915,8 +1917,13 @@ static int dsortf(struct ent **e1, struct ent **e2)

/*
* First, see if either of the entries is for the parent directory.
* If so, that *always* sorts lower than anything else.
* If so, that *always* sorts lower than anything else. The
* function must be transitive else behaviour is undefined, although
* in no real case should both entries start with a '/'.
*/
if ((*e1)->name[0] == '/' && (*e2)->name[0] == '/') {
return 0;
}
if ((*e1)->name[0] == '/') {
return -1;
}
Expand Down
42 changes: 40 additions & 2 deletions test/modules/generators/test_002_autoindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@
class TestAutoindex:

@pytest.fixture(autouse=True, scope='class')
def _class_scope(self, env):
@classmethod
def _class_scope(cls, 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
<If "%{{QUERY_STRING}} == 'xhtml'">
IndexOptions XHTML Charset=ISO-8859-2
</If>
<ElseIf "%{{QUERY_STRING}} == 'nocharset'">
IndexOptions Charset=
</ElseIf>
<ElseIf "%{{QUERY_STRING}} == 'charset'">
IndexOptions Charset=ISO-8859-2
</ElseIf>
<Else>
IndexOptions FancyIndexing ScanHTMLTitles
</Else>
</Directory>
"""),
})
Expand All @@ -32,3 +44,29 @@ def test_generators_002_01_scan_title_bare_amp(self, env):
r = env.curl_get(env.mkurl("http", "autoindex", "/listing/"))
assert r.response["status"] == 200
assert "AT&T" in r.response["body"].decode()

def test_generators_002_02_charset_meta_html(self, env):
"""IndexOptions Charset= adds a <meta> to the HTML 4.01 document,
before <title>, without XHTML-style self-closing."""
r = env.curl_get(env.mkurl("http", "autoindex", "/listing/?charset"))
assert r.response["status"] == 200
body = r.response["body"].decode()
meta = '<meta http-equiv="Content-Type" content="text/html; ' \
'charset=ISO-8859-2">'
assert meta in body, body
assert body.index(meta) < body.index("<title>"), body

def test_generators_002_03_charset_meta_xhtml(self, env):
r = env.curl_get(env.mkurl("http", "autoindex", "/listing/?xhtml"))
assert r.response["status"] == 200
body = r.response["body"].decode()
meta = '<meta http-equiv="Content-Type" content="text/html; ' \
'charset=ISO-8859-2" />'
assert meta in body, body
assert body.index(meta) < body.index("<title>"), body

def test_generators_002_04_empty_charset_no_meta(self, env):
r = env.curl_get(env.mkurl("http", "autoindex",
"/listing/?nocharset"))
assert r.response["status"] == 200
assert "http-equiv" not in r.response["body"].decode()
Loading